Skip to main content
Known Participant
May 8, 2013
Answered

Instance name is null?

  • May 8, 2013
  • 1 reply
  • 987 views

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)

                    }

This topic has been closed for replies.
Correct answer Ned Murphy

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.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
May 9, 2013

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.

as3pandaAuthor
Known Participant
May 9, 2013

I'm so dumb, you right, I shouldn't have added to stage.