Skip to main content
Participant
August 7, 2015
Answered

I want to get property of previous object from array

  • August 7, 2015
  • 1 reply
  • 263 views

Hi

Here is my code

for(var i in MovieClip(root).arrySpt){

  var btn:MovieClip = MovieClip(box);

  //duplicate the movielcip (add a new one to the stage)

  var ClassDefinition:Class = Class(getDefinitionByName(getQualifiedClassName(btn)));

  var myMC:MovieClip = new ClassDefinition;

  myMC.inBin.text = MovieClip(root).arrySpt;

  trace(getChildByName("myMCC"+i as String).width);

  myMC.x = i * myMC.width;

  myMC.y = 0;

  myMC.velocityY = 0;

  box.addChild(myMC);

  box.boxin.visible = false;

}

  var myMC:MovieClip = new ClassDefinition;

     Here movieclips are creating and this line of code is assigning the position

myMC.x = i * myMC.width;


Here the width is assigning to X position of current object but I want assign width as X position to next object not current object. Mean If movieclip generate it should get width from previous movieclip from array.


please help me to solve this problem.


thanks

This topic has been closed for replies.
Correct answer kglad
use:

var prevX:int= 0 ;

for(var i in MovieClip(root).arrySpt){

  var btn:MovieClip = MovieClip(box);

  //duplicate the movielcip (add a new one to the stage)

  var ClassDefinition:Class = Class(getDefinitionByName(getQualifiedClassName(btn)));

  var myMC:MovieClip = new ClassDefinition;

  myMC.inBin.text = MovieClip(root).arrySpt;

  trace(getChildByName("myMCC"+i as String).width);

  myMC.x = prevX;

prevX+=myMC.width;

  myMC.y = 0;

  myMC.velocityY = 0;

  box.addChild(myMC);

  box.boxin.visible = false;

}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
August 7, 2015
use:

var prevX:int= 0 ;

for(var i in MovieClip(root).arrySpt){

  var btn:MovieClip = MovieClip(box);

  //duplicate the movielcip (add a new one to the stage)

  var ClassDefinition:Class = Class(getDefinitionByName(getQualifiedClassName(btn)));

  var myMC:MovieClip = new ClassDefinition;

  myMC.inBin.text = MovieClip(root).arrySpt;

  trace(getChildByName("myMCC"+i as String).width);

  myMC.x = prevX;

prevX+=myMC.width;

  myMC.y = 0;

  myMC.velocityY = 0;

  box.addChild(myMC);

  box.boxin.visible = false;

}

ajaazzAuthor
Participant
August 7, 2015

Thanks Kglad its working as i want. thank you so much for this help.

kglad
Community Expert
Community Expert
August 7, 2015

you're welcome.