-
1. Re: Set instance name to variable on click
kglad Jan 17, 2011 12:59 PM (in response to BrianatArena)if there are no overlapping displayobjects, you can use:
var sectionfocus:String = new String;
addEventListener (MouseEvent.MOUSE_DOWN , setfocus );
addEventListener (MouseEvent.MOUSE_UP , tracefocus );function setfocus (event:MouseEvent):void
{
sectionfocus = event.currentTarget.name;
}function tracefocus (event:MouseEvent):void
{
trace( 'Section focus is on ' + sectionfocusF(event.stageX,event.stageY));// I would like it to return "Section focus is on section101" right now it returns "Section focus is on root1"
}function sectionfocusF(x:Number,y:Number):DisplayObject{
for(var i:uint=0;i<this.numChildren;i++){
if(this.getChildAt(i).hitTestPoint(x,y)){
return this.getChildAt(i);
}
}
return null;
}
-
2. Re: Set instance name to variable on click
BrianatArena Jan 17, 2011 1:22 PM (in response to kglad)This traces:
Section focus is on [object Shape]
-
3. Re: Set instance name to variable on click
kglad Jan 17, 2011 1:36 PM (in response to BrianatArena)if you have shapes on stage that you don't want to include in the hittest, use an if-statement to prevent their return.
-
4. Re: Set instance name to variable on click
BrianatArena Jan 17, 2011 1:48 PM (in response to kglad)Thank you, after excluding a shape that was underneath everything, it traced [object MovieClip], then I tried changing the line that says sectionfocusF(event.stageX,event.stageY) to sectionfocusF(event.stageX,event.stageY).name and it is now does what it's supposed to.
-
5. Re: Set instance name to variable on click
kglad Jan 17, 2011 2:35 PM (in response to BrianatArena)great.
please mark helpful and correct answers.


