Copy link to clipboard
Copied
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.
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.
use:
function clear_blockF():Void{
for(var i:Number=block.length-1;i>=0;i--){
this[block].removeMovieClip();
}
block.length=0;
}
Copy link to clipboard
Copied
use:
function clear_blockF():Void{
for(var i:Number=block.length-1;i>=0;i--){
this[block].removeMovieClip();
}
block.length=0;
}
Copy link to clipboard
Copied
Thanks again kglad. You're a saviour.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now