Need help with ActionScript

Discussion in 'Computer Programming, Emulation, and Game Modding' started by Wabsta, Dec 11, 2009.

  1. Wabsta
    OP

    Wabsta you fight like a dairy farmer

    Member
    3
    Apr 25, 2008
    Netherlands
    SCUMM Bar
    So, I got myself a little game.
    Where a MovieClip(sprite, coin, character, whatever you'd like to call it) moves from one side to the other.
    This works, I also managed to get it away when I click it, and it adds points, that it shows on the top of the screen.

    The thing is, I want to add more of these coins to the level.
    But I don't really know how to do this.
    Now I just use
    Code:
    var coin:Coin = new Coin();
    ÂÂÂÂÂÂÂÂÂÂÂÂcoin.x = 100;
    ÂÂÂÂÂÂÂÂÂÂÂÂcoin.y = 200;
    ÂÂÂÂÂÂÂÂÂÂÂÂaddChild(coin);
    to add a coin.
    With an addEventListenere to see if the coin has collision, and if it is clicked.

    So, I want more of these coins, each with their own eventlistener.
    How should I do this? I'm thinking of creating a new class for this Coins, but I don't really know where to start.
    Could anyone help me?
     
  2. Raki

    Raki GBAtemp Advanced Fan

    Member
    1
    Jul 16, 2008
    Gambia, The
    well I have no idea of actionscript but in general programming:

    You could just create a new instance of coin (e.g. CoinA = new Coin; CoinB = new Coin and so on)
    Or you could create a Array of coins, but I guess you won't get those eventlisteners then
     
  3. Wabsta
    OP

    Wabsta you fight like a dairy farmer

    Member
    3
    Apr 25, 2008
    Netherlands
    SCUMM Bar
    Hmmyea, I tried the array idea, this is what I have now:
    CODEÂÂÂÂÂÂÂÂÂÂÂÂvar myArray:Array = new Array();
    ÂÂÂÂÂÂÂÂÂÂÂÂvar timeArray:Array = new Array();
    ÂÂÂÂÂÂÂÂÂÂÂÂfor(var i:int = 0; i < 10; i++)
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ{
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂvar Container:Coin = new Coin();
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂvar coinTimer:Timer = new Timer(800);
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂvar random1:Number = Math.floor(Math.random()*384)+1;
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂContainer.x = 64;
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂContainer.y = random1;ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂmyArray = Container;
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂaddChild(myArray);
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂtimeArray = coinTimer;
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂtimeArray.addEventListener(TimerEvent.TIMER, animateCoin);
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂfunction animateCoin(event:Event)
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ{
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂmyArray.x += 1;
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂif (myArray.currentFrame == 28) {
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂmyArray.gotoAndStop(1);
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ} else {
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂmyArray.gotoAndStop(myArray.currentFrame+10);
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ}
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ}
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂtimeArray.start();
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ}
    But ofc it doesn't work, it doesnt want to go to that function of animatecoin I think..
    What could I try?

    EDIT: Formatting
    EDIT2: Nvm, got it, Im done with the game now [​IMG]
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice