Need help with ActionScript

Wabsta

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

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    K3Nv2 @ K3Nv2: https://youtube.com/shorts/Tt5J7AfCK6E?si=g4dGzOkhACLJAovM