Groups | Blog | Home
all groups > flash actionscript > january 2006 >

flash actionscript : How to address dynamically created movies


rooster_asu
1/9/2006 10:39:44 PM
I'm building a fiber optic simulator program for my engineering design project
and I'm in need of some help because I'm in a bit over my head. I have built a
program which so far allows me to attach movies with dynamically changing names
and depths which act as fiber components, I've got one that is a laser, another
is a line drawing tool. I've managed to constrict the line movements to the
work area but now I have to take this one step further and I'm not sure how to
go about this. For the fiber component movie I have, I guess, a child movie
named connector which is just a red box. I need to have the line button to
allow drawing only when user presses the mouse over this connector movie. I
don't know how to code this because the movie name is always changing. I'm
going to submit my code it is probably the worst and most inefficient code ever
but this is my first program ever. I'll have to remember to thank my
sponsoring teacher again for coming up with this brilliant idea. For anyone
who actually takes pity and responds thank you very much I really appreciate
it, I really don't have any other resources other than two books and this
website.



Line_btn.onRelease = function(){
draw();
}
Test_btn.onRelease = function(){
createLaser();
}
//Functions
//Laser Function
function createLaser():Void{
attachMovie("Laser","Laser_mc"+i,i,{_x:300,_y:300});
i++;
}
//Fiber Line Function
function draw():Void {
var originx:Number;
var originy:Number;
var j:Number = 200;
var drawing:Boolean = false;
var mouseListener:Object = new Object();
Mouse.addListener(mouseListener);
mouseListener.onMouseDown = function(){
originx = _xmouse;
originy = _ymouse;
if(originx > 150 && originx < 800){
if(originy > 0 && originy < 600){
drawing = true;
}
}
}
mouseListener.onMouseMove = function(){
var thisSegment:MovieClip = createEmptyMovieClip("temp"+j,j);
//Number signifies which case statement will be true, 0 if in
//canvas, 1 for left bound only two for right bound etc...
var Bounds:Number = 0;
thisSegment.clear();
//Bounds Check
if (_xmouse <150){
if(_ymouse < 0){
Bounds = 5;
}
else{
if(_ymouse > 600){
Bounds = 6;
}
else{
Bounds = 1;
}
}
}
if (_xmouse > 800) {
if(_ymouse < 0){
Bounds = 7;
}
else{
if(_ymouse > 600){
Bounds = 8
}
else{
Bounds = 2;
}
}
}
if (_ymouse < 0){
Bounds = 3
}
if(_ymouse > 600){
Bounds = 4;
}
if (drawing == true){
with(thisSegment){
lineStyle(1,0x000000,100);
moveTo(originx,originy);
switch(Bounds){
case 0:
lineTo(_xmouse,_ymouse);
break;
case 1:
lineTo(150,_ymouse);
break;
case 2:
lineTo(800,_ymouse);
break;
case 3:
lineTo(_xmouse,0);
break;
case 4:
lineTo(_xmouse,600);
break;
case 5:
lineTo(150,0);
break;
case 6:
lineTo(150,600);
break;
case 7:
lineTo(800,0);
break;
case 8:
lineTo(800,600);
break;
}
}
}
}


mouseListener.onMouseUp = function(){
drawing = false;
var tempClear:MovieClip = createEmptyMovieClip("clear",200);
var finalSegment:MovieClip =
createEmptyMovieClip("finalSegment"+segment,segment);
tempClear.clear();
with (finalSegment){
if(_xmouse > 150 && _xmouse < 800){
if(_ymouse > 0 && _ymouse < 600){
lineStyle(2,0x000000,100);
moveTo(originx,originy);
lineTo(_xmouse,_ymouse);
}
}
}
segment++;
Mouse.removeListener(mouseListener);
}
}
kglad
1/10/2006 3:51:07 AM
your attached movieclip is "Laser_mc"+i and it is attached to some (namely the
timeline that contains that code) timeline. if that timeline is the _root
timeline your attached movieclip is:

_root["Laser_mc"+i]

if the attached movieclip contains a child movieclip with instance name
connector, then you can reference this movieclip by using:

_root["Laser_mc"+i].connector
rooster_asu
1/10/2006 8:34:12 PM
kglad
1/11/2006 1:33:48 AM
AddThis Social Bookmark Button