Dear all ,
I need again your help with this code.
What I am trying to do is to get the name of a movieClip in a specific point. According to next code I would expect to get the name “myMovie” using container.getChildByName(instance) but the problem is objectsBelowMouse[0].name gives my a different instance name. The container tells me that the name of the instance is “instance2” but container.getChildByName(instance) tells that the instance name is “instance3”. So when I try to get the name getQualifiedClassName (target) gives me a null. If I wrtite:
var target:DisplayObject = container.getChildByName("instance2")
trace(getQualifiedClassName (target));
I got the name “myMovie”, this is what I want
This the code:
var container:MovieClip = new MovieClip();
addChild(container);
render("myMovie",400,300);
stage.addEventListener(Event.ENTER_FRAME,mainLoop);
function mainLoop(event:Event) {
var location:Point = new Point(stage.mouseX, stage.mouseY);
var objectsBelowMouse:Array = container.getObjectsUnderPoint(location);
if (objectsBelowMouse.length >0) {
var instance:String = objectsBelowMouse[0].name
var target:DisplayObject = container.getChildByName(instance)
trace(instance);//instance3
trace(getQualifiedClassName (target));//null
trace(container.getChildAt(0).name)// instance2
}
}
function render(nameClass:String,posX:Number,posY:Number):void {
var classRef:Class = getDefinitionByName(nameClass) as Class;
var instance:Object = new classRef();
container.addChild(DisplayObject(instance));
instance.x=posX;
instance.y = posY;
}
I will appreciate your help.
Thanlks