3 Replies Latest reply on Jun 19, 2014 8:40 PM by kglad

    Problem with persistence across scenes

    basil01

      I have a student who has created some code- see below. At the moment this code is in Scene 5 - but the blocks also appear on other scenes.

      1. How does he limit this code to just one scene?
      2. Can he replicate this to be used on other scenes, but starting out fresh.

       

      Currently, 50 blocks spawn on top of one another. These are used for teaching addition or multiplication. When they've been dragged out into a pattern, we don't want that pattern on another scene, we want them on on top of the other.

       

      The code is not overly elegant, but it does work - except for being repeated across scenes.

       

      block = []

      //this function creates a block at a certain location and adds it to an array

      //new identifiers are block30 and so on

      function spawnBlock(){

        blockSpawn = attachMovie("block","block"+_root.getNextHighestDepth(),_root.getNextHighestDepth(),{_x:5 50,_y:300});

        block.push(blockSpawn._name);

      }

      //this runs the spawnBlock funtion 50 times creating 50 new blocks

      //change 50 to the number of blocks desired

      for(i=0;i<50;i++){

        spawnBlock();

        //trace(block[i]); //testing if the funtion was working

      }

      function dragSetup(clip){ //this is used to assign a movie clip to funtion that can be reused with each block that is created

        clip.onPress = function(){

        startDrag(this);

        }

        clip.onRelease = clip.onReleaseOutside=function(){ //same as above

        stopDrag();

        }

      }

      //this lets each block that is needed to be dragged

      //add in more lines to let more blocks get dragged

      dragSetup(block0);

      dragSetup(block1);

      dragSetup(block2);

      dragSetup(block3);

      dragSetup(block4);

      dragSetup(block5);

      dragSetup(block6);

      dragSetup(block7);

      dragSetup(block8);

      dragSetup(block9);

      remainder removed for brevity.