Skip to main content
Participant
November 29, 2018
Question

Can I access a property of a movieclip in this way??

  • November 29, 2018
  • 1 reply
  • 187 views

`I want to put in a displayobjectcontainer many movieclip derivatives called snailMovieClip and batMovieClip, which are all derivatives of movieclip class and they all additionally have a parameter called thisMonstersIDnumber added into the classes.. As this would go and answer the question for any type of movieclip derivative you may have in your game/production, Can you search for a displayobjectcontainer for any type of "dot variables" (i think theyre called properties) that you have from classes of movie clip added to that displayobjectcontainer? Here this is what i mean. "Can I find a snailMovieClip or batMovieClip using its monsterIDnumber by searching a displayobjectcontainer by monsterIDnumber? 

//populating a displayobjectcontainer with movieclips of class snailMovieClip

var monsterIDnumberDesignator:Number=0;

for i:0 i++ i<=5

var newMonster: snailMovieClip = new snailMovieClip(monsterIDnumberDesignator)

monsterIDnumberDesignator++;

maindisplayframe.addChild(newMonster)

(...in snailMovieClip class)

package

{

var thisMonstersIDNumber:Number=0

public function  snailMovieClip(this_Monsters_ID_Number)

{

thisMonstersIDNumber=this_Monsters_ID_Number;

}

}

//and NOW....

for j:Number=0; j++; j<=maindisplayframe.numChildren

trace maindisplayframe.getChildAt(j).thisMonstersIDNumber

??????????????????^^^^^^^^^^can I do this??

This topic has been closed for replies.

1 reply

JoãoCésar17023019
Community Expert
Community Expert
November 29, 2018

Hi.

The getChildAt method returns a DisplayObject and by default display objects don't have a property called monstersIDNumber.

So you have to tell the compiler that your object has that property by using casting. Like this:

for (var i:uint = 0; i < yourContainer.numChildren; i++)

    trace((yourContainer.getChildAt(i) as snailMovieClip).monstersIDNumber);

I hope this helps.

Regards,

JC