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

How can I search the stage for a given Movieclip and then add all instances of it to an Array? AS3

New Here ,
Apr 03, 2014 Apr 03, 2014

I would like to Add multible instances of one Movieclip, (Library Name = Bats | instance name = none), inside of another Movieclip (instance name = back.visuals) // (By HAND) NOT by addChild(mc_name); // Easy

If anyone could help me out with code to do the next steps:

Search the Movieclip, (instance name = back.visuals), that contains the Movieclips, (Library Name = Bats | instance name = none), manually added to the stage by hand.

Then for all instances of this movieclip (Library Name = Bats | instance name = none) add them to an Array.

Thank You,

Dyami

TOPICS
ActionScript
1.9K
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

correct answers 1 Correct answer

LEGEND , Apr 03, 2014 Apr 03, 2014

Assuming you are talking about runtime, if you export symbol for action script and give it a Class name you can always read whether child of an object is an instance of this symbol.

Say, if symbol name is Bats you can identify it in the loop as following:

var enemyList:Array = [];

for (var i:int = 0; i < back.visuals.numChildren; i++)

{

          var child:DisplayObject = back.visuals.getChildAt(i);

          if (child is Bats)

          {

                    enemyList.push(child);

          }

}

Translate
Community Expert ,
Apr 03, 2014 Apr 03, 2014

you want to search in the ide?

are you using flash pro cc?

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
New Here ,
Apr 03, 2014 Apr 03, 2014

I am using Flash Pro CC.

I want to search a MovieClip container I manually added to the stage/"Timeline" and gave an instance name of (back.visuals) for all instances of a different Movieclip (with no stage/"TimeLine" instance name) and add all instances of that Movieclip to an Array.

So I guess no I do not want to use the Library Search Function on the IDE.

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 ,
Apr 03, 2014 Apr 03, 2014

either use jsfl or use an earlier version of flash pro.

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
New Here ,
Apr 03, 2014 Apr 03, 2014

I think we are having some missed communication. I do not wish to Change Flash's IDE or deveolp new features for flash. I was wondering if there was a way to do my question with AS3. something along the lines of :

var enemyList:Array = new Array;
for (var index:int = 0;index < back.visuals.numChildren;index++)
{
   
var wall:MovieClip = back.visuals.getChildAt(index) as MovieClip;

/* Check to see if wall is of a Specfic MovieClip */

/* if (Above is True){ enemyList.push(wall) };

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
LEGEND ,
Apr 03, 2014 Apr 03, 2014

Assuming you are talking about runtime, if you export symbol for action script and give it a Class name you can always read whether child of an object is an instance of this symbol.

Say, if symbol name is Bats you can identify it in the loop as following:

var enemyList:Array = [];

for (var i:int = 0; i < back.visuals.numChildren; i++)

{

          var child:DisplayObject = back.visuals.getChildAt(i);

          if (child is Bats)

          {

                    enemyList.push(child);

          }

}

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 ,
Apr 04, 2014 Apr 04, 2014

in general the answer to your question is, no.  you cannot determine symbol names (or library names) using actionscript.  you can using jsfl during author-time and using cs6's search panel during author-time.

using actionscript (ie, during run-time) you are much more limited, but can check class name (as indicated by andrei1) or other object properties if you have some combination of those that select the objects of interest..

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
Guide ,
Apr 04, 2014 Apr 04, 2014
LATEST

You're probably better off just watching the display list and checking as objects get added, rather than going back after the fact.

so:

protected var things:Vector.<YourType> = new Vector.<YourType>;

protected function init():void {

     stage.addEventListener(Event.ADDED_TO_STAGE, addYourTypeOfThingToVector, true);

}

protected function addYourTypeOfThingToVector(e:Event):void {

     var thing:YourType = e.target as YourType;

     if (thing) {

          things[things.length] = thing;

          thing.addEventListener(Event.REMOVED_FROM_STAGE, removeYourTypeOfThing);

     }

}

protected function removeYourTypeOfThing(e:Event):void {

     var thing:YourType = e.target as YourType;

     if (thing) {

          thing.removeEventListener(Event.REMOVED_FROM_STAGE, removeYourTypeOfThing);

          var index:int = things.indexOf(thing);

          if (index>0) {

               things.splice(index, 1);

          }

     }

}

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