Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Nov 29, 2018 Nov 29, 2018

`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??

TOPICS
ActionScript
174
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 29, 2018 Nov 29, 2018
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines