Need help with ActionScript

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

Dec 11, 2009

Need help with ActionScript by Wabsta at 10:12 AM (630 Views / 0 Likes) 2 replies

  1. Wabsta
    OP

    Member Wabsta you fight like a dairy farmer

    Joined:
    Apr 25, 2008
    Messages:
    2,485
    Location:
    SCUMM Bar
    Country:
    Netherlands
    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

    Member Raki GBAtemp Advanced Fan

    Joined:
    Jul 16, 2008
    Messages:
    554
    Country:
    Germany
    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

    Member Wabsta you fight like a dairy farmer

    Joined:
    Apr 25, 2008
    Messages:
    2,485
    Location:
    SCUMM Bar
    Country:
    Netherlands
    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]
     

Share This Page