0

I make a global variable equal to a movieclip

A function gets run with an if statement checking if [x] movieclip exists, if it doesn't add it. Despite the MovieClip being on the stage it continues using the if statement.

Document class

public static var skinHolder:MovieClip = new test;

Seperate Class (function runs every frame)

    function animHandler():void
    {
        if (! Game.skinHolder.stage)
        {
            // if its not on the stage we add it to the stage
            addChild(Game.skinHolder);
        }

    }
UnAlpha
  • 127
  • 14
  • `trace("check status : " + (Game.skinHolder.stage) ); if (! Game.skinHolder.stage) { rest of code...` what did the trace say about status? You need one result so try to avoid _EnterFrame_ just for this check _ie:_ just `//`comment the addEvent line then manually run function as `animHandler();` – VC.One Mar 31 '17 at 08:15
  • check status : null – UnAlpha Mar 31 '17 at 21:38
  • You are adding your `Game.skinHolder` to the `SeparateClass` instance. Are you sure your `SpearateClass` instance is added in display list first? Your `SpearateClass` have to also be on stage for it's children to have access to stage. – Paweł Audionysos Apr 01 '17 at 13:40
  • My document class adds the SeperateClass – UnAlpha Apr 01 '17 at 14:37
  • If my document class is not adding it to the stage, how can I do so? – UnAlpha Apr 01 '17 at 14:38
  • Your "Separate Class" must not be on the stage. `addChild()` doesn't add anything to the stage, it adds it to the current display object, and if that object is not on the stage, well nothing is added to the stage. – Aaron Beall Apr 04 '17 at 15:40
  • I tried changing the way I add the class, from addChild() to stage.addChild() it still gives the same outcome. I simply want to add it to the stage and check if those objects I add are on the stage. – UnAlpha Apr 04 '17 at 21:04

2 Answers2

0

The stage is not set immediately after a MovieClip is added, usually it happens on the next frame.

It is an odd way to check if an object exist though, you should do something like this:

private var mySkinHolder:MovieClip;

if (!mySkinHolder)
{
    // if it not exist we add it to the stage
    mySkinHolder = addChild(new test());
}
Philarmon
  • 1,796
  • 1
  • 10
  • 14
0

I don't completely understand your structure, but to check if a DisplayObjectContainer (MovieClip in your case) has a specific child, you can use the contains() method.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html#contains()

if (!contains(Game.skinHolder)) {
    addChild(Game.skinHolder);
}
Patang
  • 314
  • 2
  • 8