A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: If MovieClip exists

  1. #1

    If MovieClip exists

    Quite a simple question this one. I'm trying to prevent code being called on a DisplayObject if it doesn't exit.
    This throws up an error
    Code:
    if (mc)
    {
    	trace(mc);
    }
    Throws up the following error
    1120: Access of undefined property mc.
    I've tried if(mc.stage), if (contains(mc)) and if (this.getChildByName("mc")) and none of them seem to work

    Using Flash PLayer 9 in CS6

    Thanks

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    You at least need to declare mc if it is not already on the stage, or it will throw an error like the one you have.

    PHP Code:
    var mc:MovieClip;

    if (
    mc)
    {
        
    trace(mc);
    }
    else
    {
        
    trace("mc not on stage");


  3. #3
    That worked, thanks

    Strange, I don't remember this being an issue before. Perhaps I was thinking in AS2

    Quote Originally Posted by fruitbeard View Post
    Hi,

    You at least need to declare mc if it is not already on the stage, or it will throw an error like the one you have.

    PHP Code:
    var mc:MovieClip;

    if (
    mc)
    {
        
    trace(mc);
    }
    else
    {
        
    trace("mc not on stage");


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center