Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-12-2012, 11:51 PM   #1
TJRobertson86
Registered User
 
Join Date: Apr 2012
Posts: 37
Red face [AS3] Can't get replay button to work

I'm just finishing up my first flash game (thanks to many people on this forum, especially lauri), and I'm having a couple issues, but my main one is getting the replay button at the Win/Lose screen to work.

I tried using some code I found from another thread on this forum, but I still couldn't get it to work. It's possible that I just didn't understand how to implement the code. Here's what I was trying:

Code:
replay_btn.onRelease = function(){
loadMovieNum("yourgame.swf", 0);
};
I also tried having the button re-run my "initiate game" function (which sets all the game values to their starting state), but that doesn't seem to be doing anything.

Any help would be very much appreciated

Here's my swf: tjrobertson.com/games/beegamev3.html
And my fla: tjrobertson.com/games/beegamev3.fla

I apologize if my code is messy. The replay button function can be found on lines 415 - 422 of the main timeline... altho it's not doing anything at the moment.

Thank you!
TJ
TJRobertson86 is offline   Reply With Quote
Old 04-13-2012, 04:35 AM   #2
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,397
Default

the code you posted there is AS2; won't work in AS3.
[afz]snickelfitz is offline   Reply With Quote
Old 04-13-2012, 04:02 PM   #3
TJRobertson86
Registered User
 
Join Date: Apr 2012
Posts: 37
Default

That explains why it wasn't working =P Thank you..

Any idea how I would accomplish this in AS3?
TJRobertson86 is offline   Reply With Quote
Old 04-13-2012, 04:34 PM   #4
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,982
Default

You use Event Listeners in as3, I think MouseEvent.MOUSE_UP is equivalent to onRelease

Maybe this instead of loadMovieNum ?
Code:
var game:Loader =  new Loader(new URLRequest("yourgame.swf"));
addChild(game);
rrh is offline   Reply With Quote
Old 04-15-2012, 12:27 AM   #5
TJRobertson86
Registered User
 
Join Date: Apr 2012
Posts: 37
Default

@rrh Thanks for that code. I still couldn't get it to work =/

However, from reading more on the forums, it seems like the "proper" way to code a replay button is just to reset everything to its original state.

I'm trying to remove all the event listeners and children and re-run the initialize game function. My problem now is I can't figure out how to remove all children from a given array.

This is the loop I'm trying right now:

Code:
while (ba.numChildren) 
	{
    ba.removeChildAt(0);
	}
But it doesn't seem to do anything... any ideas?

Here's the fla, in case anyone wants to take a closer look at my code: tjrobertson.com/games/beegamev3.fla

And the SWF: tjrobertson.com/games/beegamev3.html

Any help would be appreciated

Thank you,
TJ
TJRobertson86 is offline   Reply With Quote
Old 04-15-2012, 12:35 AM   #6
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,397
Default

reset an Array:
ActionScript Code:
myArray = [];
[afz]snickelfitz is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:08 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.