Question

Hey I'm new to Flash AS 3.0 and I am having trouble with creating instances of classes and want to Control them using a single function for all of them.

import flash.display.MovieClip;
import flash.events.*;
stage.addEventListener (KeyboardEvent.KEY_DOWN, movestuff);

var newsymbol:MovieClip;
newsymbol = new Symbol1;
addChild(newsymbol);
newsymbol.x = 200
newsymbol.y = 200
addChild(newsymbol);

function movestuff (event:KeyboardEvent):void
{

newsymbol.x + 100
}

Symbol1 is a class from the library that I am trying to move, and I want to add multiple instances of it but control all of them using the function movestuff

Was it helpful?

Solution

Keep the instances in an array:

var penguinArray:Array = [];

function addPenguin(){
    var newPenguin:Penguin = new Penguin();
    //do stuff
    penguinArray.push(newPenguin);
}

function moveStuff(){
    for(var i in penguinArray){
        penguinArray[i].x += 10;
    }
}

OTHER TIPS

Is your movement that uniform between all of them (do you want to move them all by the same x and y)? If so, put them all inside one parent movie clip and only move that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top