Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 5 of 5

Thread: cannot convert flash.display::Sprite

  1. #1

    cannot convert flash.display::Sprite

    cannot convert flash.display::Sprite@39394a9 to flash.display.MovieClip.
    here is sample code
    Code:
    var enemyArray:Array = new Array();
    var mySprite:Sprite;
    mySprite = new Sprite();
    addChild(mySprite);
    var myEnemy:Enemy;
    myEnemy = new Enemy();
    mySprite.addChild(myEnemy);
    enemyArray.push(myEnemy);
    removeEnemy(e:Enemy)
    {
       for(var i in enemyArray)
       {
          if(enemyArray[i] == e)
          {
             enemyArray.splice(1,i);
          }
    }
    }
    enemy class: if anemy is offscreen he will call the deleteEnemy
    then it will delete the enemy from stage after that it will call removeChild() from the parent to remove the enemy from the array
    Code:
    deleteEnemy()
    {
       MovieClip(parent).removeEnemy(this);
       parent.removeChild(this);
    }
    then it will get the error above

    i guess the problem is, enemy class cant access the removeEnemy() in parent class
    but when i remove the sprite like this:
    Code:
    addChild(myEnemy);
    rather than this:
    Code:
    mySprite.addChild(myEnemy);
    then it will be ok, but my goal is, How can enemy call the removeEnemy() in parent while it is inside the sprite, tnx for the help in advance...
    Last edited by senocular; November 1st, 2010 at 07:09 PM. Reason: added [code] tags

  2. #2
    Use Object(parent).

    MovieClip(parent) is not the magic fix-all solution for parent referencing. Its a cast, and for a cast to succeed, it has to be the same type as the type of object being cast. If parent is not a movie clip, the cast will fail. Using Object, the cast will pass and you'll be able to use whatever reference you want since Object is a dynamic type.

    The most correct approach would be to cast to the actual type of what parent really is.

  3. #3
    Object(parent).removeEnemy(this);

    Error #1069: Property removeEnemy not found on flash.display.Sprite

    still enemy cant find the removeEnemy() function in main while its in the sprite

    but when i remove him from the sprite, it can call the removeEnemy() on main

    how does enemy cant find the removeEnemy() while the enemy is inside the sprite?, tnx..

  4. #4
    Then removeEnemy is not in the parent

  5. #5
    Quote Originally Posted by senocular View Post
    Then removeEnemy is not in the parent
    its not in main its in the other movieClip ex: sample(MovieClip), sorry for the mistake ^_^

    here is the structure if no sprite

    main > sample > Enemy

    sample(MovieClip) is the parent of enemy where the enemy try to call the removeEnemy
    from the sample

    removeEnemy is inside the sample class..


    then if have sprite

    main > sample > sprite > enemy

    now enemy cant call the removeEnemy() in the sample
    Last edited by frogtoon; November 1st, 2010 at 07:52 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012