-2

I tried to access the movieclip using its name but failed.

TypeError: Error #1009: Cannot access a property or method of a null object reference.

var i = 5;
var me:Array = new Array("num1-xd", "num2-xd2","num3-xd3");
var cool:Array;
var sq:Square;
for each(var wew:Object in me)
{
    //trace(me);
    cool = wew.split("-");
    sq = new Square();
    sq.x = 3;
    sq.y = sq.height + i;
    i += sq.height + 4;
    sq.name = String(cool[1]);
    sq.instanceName = String(cool[1]);
    addChild(sq);
    sq.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void
    {
        trace(e.target.name);
    });
}

stage.addEventListener(MouseEvent.CLICK, KeyisDown);
function KeyisDown(e:MouseEvent)
{
    var me2:String = "xd";
    var me3:DisplayObject = stage.getChildByName(me2);
    me3.x += 5;
}

I can't access xd movieclip on the stage and make it move.

mickmackusa
  • 43,625
  • 12
  • 83
  • 136

2 Answers2

0

Assuming you just have the movieclips on the main timeline you could try this["xd"].x += 5; or this[me2].x += 5;

Andrew Sellenrick
  • 996
  • 1
  • 6
  • 8
0

If you declared the variables on stage

Use:

this.xd

this.xd.x += 5;

John Pangilinan
  • 953
  • 1
  • 8
  • 25