Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Problem with persistence across scenes

Community Beginner ,
Jun 17, 2014 Jun 17, 2014

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:550,_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); //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.

TOPICS
ActionScript
200
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 18, 2014 Jun 18, 2014

use:

function clear_blockF():Void{

for(var i:Number=block.length-1;i>=0;i--){

this[block].removeMovieClip();

}

block.length=0;

}

Translate
Community Expert ,
Jun 18, 2014 Jun 18, 2014

use:

function clear_blockF():Void{

for(var i:Number=block.length-1;i>=0;i--){

this[block].removeMovieClip();

}

block.length=0;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 19, 2014 Jun 19, 2014

Thanks again kglad. You're a saviour.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 19, 2014 Jun 19, 2014
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines