1 Reply Latest reply on Mar 13, 2010 3:55 PM by kglad

    attachMovie not working if Object Used Elsewhere!




      I'm making a flash lite 2.1 (AS2.0) game when i came across a very annoying, and interesting error.  Took me several hours to track down.


      function createUnit(spawnPoint) {
           if (Math.random()<0.8) {
                //  Create and attach Unit to codeLine.
                spawnPoint.myUnit = spawnPoint.attachMovie(goodUnitType, 'Unit'+spawnPoint.getNextHighestDepth(), spawnPoint.getNextHighestDepth());
                spawnPoint.myUnit.good = true;
           } else {
                spawnPoint.myUnit = spawnPoint.attachMovie(evilUnitType, 'Unit'+spawnPoint.getNextHighestDepth(), spawnPoint.getNextHighestDepth());
                spawnPoint.myUnit.good = false;


      This is a small snipit with which I use to create a unit, and attach it to my spawner.  It works fine.


      However, if in any preceding frame i use one of the "goodUnitType" as a demo (just dragged and dropped on the screen), it fails miserably.


      instead of (e.g.) spawnPoint.myUnit = _level0.spawnPoint2.Unit5

      it returns function spawnPoint.myUnit = _level0.spawnPoint2


      Which stuffs up code that needs this.


      So why is attachUnit being so temperamentall?


      If you need more code just ask.


      Example level below - its easy to see where I want to display the unit.

      http://www.megafileupload.com/en/file/205664/v25-Level-1-swf.html (sorry for crappy waiting time).


      Note:  Doesn't have a problem if i add it programicaly earlier - only if a drop it on the stage.