Copy link to clipboard
Copied
I generated a list of movieclip that contain different text.
for(var i:int=0;i<locationarray.length;i++) {
locationmc=new locationname();
addChild(locationmc)
locationmc.name="loc1"
locationmc.locationtxt.text=locationarray;
locationmc.x = Math.floor(Math.random() * 500);
locationmc.y = Math.floor(Math.random() * 300);
locationmc.y=100;
locationmc.x=200;
trace(locationmc.name)
locationobject.push(locationmc)
locationmc.addEventListener(MouseEvent.MOUSE_DOWN,mousedown)
locationmc.addEventListener(MouseEvent.MOUSE_UP,mouseup)
stage.addEventListener(MouseEvent.CLICK,testobject);
}
But when I do a check on the instance name it would show up null, code for the checking is as follows
public function testobject(e:Event){
trace(e.target.name)
trace(e.currentTarget.name)
}
It is possible e.target is not what you think it is. Try tracing e.target to see what you are trying to get a name from. When you trace e.currentTarget you are going to get the object that has the listener assigned, which in this case is the stage, which does not implement a name property.
Copy link to clipboard
Copied
It is possible e.target is not what you think it is. Try tracing e.target to see what you are trying to get a name from. When you trace e.currentTarget you are going to get the object that has the listener assigned, which in this case is the stage, which does not implement a name property.
Copy link to clipboard
Copied
I'm so dumb, you right, I shouldn't have added to stage.
Copy link to clipboard
Copied
Another question, I have bunch of movieclip placed on stage already with different instance name, is there a way to select them in the as file? I tried getChildByName("loc1").addEventListener(MouseEvent.CLICK,test) but it seem to be null.
Copy link to clipboard
Copied
If you have an object you placed on the stage with an instance name of loc1 assigned to it, then all you should need to do is use...
loc1.addEventListener(MouseEvent.CLICK,test);
But that might not work if the as file is not the document class and the as file has no reference to objects on the stage..
Copy link to clipboard
Copied
It doesn't seem to work I tried to declear it on top public var loc1:MovieClip but it would still gave error 1009, and when I try to put a list of loc in array it appear to be null as well
var targetarray:Array=new Array(loc1,loc2,loc3,loc4,loc5,loc6,loc7,loc8,loc9,loc10,loc11,loc12)
Copy link to clipboard
Copied
but suprisingly, when I put the code on frame it would work, I don't understand why
Copy link to clipboard
Copied
never mind, I fixed, thank you anyway
Find more inspiration, events, and resources on the new Adobe Community
Explore Now