Need help with ActionScript

Wabsta

you fight like a dairy farmer
OP
Member
Joined
Apr 25, 2008
Messages
2,495
Trophies
0
Age
31
Location
SCUMM Bar
Website
www.wabsta.com
XP
438
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?
 

Raki

Well-Known Member
Member
Joined
Jul 16, 2008
Messages
554
Trophies
0
XP
98
Country
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
 

Wabsta

you fight like a dairy farmer
OP
Member
Joined
Apr 25, 2008
Messages
2,495
Trophies
0
Age
31
Location
SCUMM Bar
Website
www.wabsta.com
XP
438
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
smile.gif
 
General chit-chat
Help Users
  • Xzi @ Xzi:
    OMG THAT'S DISGUSTING, where would one find the best AI art sites/apps so they can avoid them?
  • Veho @ Veho:
    Captain America, when the reference was understood.
    +1
  • Veho @ Veho:
    Dunno about other sites but I saw it on e-hentai.
    +1
  • Veho @ Veho:
    Search the "misc" tab for "generated" and you'll get a million galleries, but I recommend you filter by rating, 4 stars or more.
    +1
  • Xzi @ Xzi:
    and it allows you to generate your own I assume?
  • Veho @ Veho:
    I can post this here because it's PG13.
  • Xzi @ Xzi:
    holy fuck
  • DinohScene @ DinohScene:
    need more male
  • Veho @ Veho:
    I mean you can tell it's not a real photo, that it's been edited at least, but I would never believe this was a drawing, made BY a computer.
  • Xzi @ Xzi:
    yeah really only a few tells that its not real
  • Xzi @ Xzi:
    crazy that it's already this advanced, in a decade all the best fap material will be AI-generated
  • ZeroT21 @ ZeroT21:
    Looks obvious
  • Xzi @ Xzi:
    if it doesn't kill us first
  • ZeroT21 @ ZeroT21:
    who cares... [dies happy]
  • Veho @ Veho:
    When I was a kid this is what digital images of women looked like:
  • ZeroT21 @ ZeroT21:
    till we got leotard samus
  • ZeroT21 @ ZeroT21:
    don't ever say ninty didn't give fanservice
  • Veho @ Veho:
    Yeah, those three flesh-colored pixels blew my mind.
  • ZeroT21 @ ZeroT21:
    gud times
  • Veho @ Veho:
    Nowadays we can just tell Google to plug our search history into Midjourney and generate us bespoe porn tailored exactly to our tastes.
  • GwenHalbaida @ GwenHalbaida:
    I LOVE IT! Midjourney is the best
    GwenHalbaida @ GwenHalbaida: I LOVE IT! Midjourney is the best