1

I have about 1000 objects on the scene, each with specific symbol name ("instance of"), and with blank instance name. Can I somehow get symbol name when I click on one of those objects? Can I reference such objects, set them x, y etc...? Thanks!

3 Answers3

0

The as2 / as3 issues is relevant.

it depends on what you mean by click. if you are running a flash application , yes you can register an event listener to get the position when you click on an instance of a symbol. Symbols needs a name when you need to access them from the parent on the timeline.

You can access the children of a MovieClip with the getChildAt(index) method and get the number of children with the numChildren field i AS3 :

http://livedocs.adobe.com/flash/9.0_fr/ActionScriptLangRefV3/flash/display/MovieClip.html#methodSummary

mpm
  • 20,148
  • 7
  • 50
  • 55
0

Yes, if you are using AS3, follow the below procedure:

Loop through each object and add a click event:

myObject1.addEventListener(MouseEvent.Click, onClick);

Create the method to handle the event being listened to:

function onClick(e:MouseEvent) {
   var myObject:Sprite = e.currentTarget as Sprite;

   myObject.x = 10; // etc

}

This will allow you to grab a reference of an object once clicked and manipulate it.

Jonathan Dunlap
  • 2,581
  • 3
  • 19
  • 22
0

to see it in action: http://wonderfl.net/c/hJVd

i used getChildAt instead of symbole name:

package {
    import flash.events.MouseEvent;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            var container_mc:MovieClip = new MovieClip();
            this.addChild(container_mc);
            var new_mc:MovieClip;

            for(var i:int=0;i<50;i++){
                new_mc = new MovieClip();
                new_mc.graphics.beginFill(Math.random()*0xFF0000,08);
                new_mc.x = Math.random()*stage.stageWidth;
                new_mc.y = Math.random()*stage.stageHeight;
                new_mc.graphics.drawCircle(0,0,20);
                new_mc.graphics.endFill();
                //new_mc.addEventListener(MouseEvent.MOUSE_DOWN,pressMc);//you can add event here or[2*]
                container_mc.addChild(new_mc);
            }
            //[2*]if you have already childs inside parent MovieClip:

            var totalChilds:int = container_mc.getChildNums;
            for(var c:int=0;c<totalChilds;c++){
                var mychild_mc:* = container_mc.getChildAt(c);
                mychild_mc.addEventListener(MouseEvent.MOUSE_DOWN,pressMc);
            }
            function pressMc(e:MouseEvent):void{
                trace(e.target);
            }
        }
    }
}
mgraph
  • 15,238
  • 4
  • 41
  • 75