Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-13-2012, 01:55 PM   #1
01matthewst
Registered User
 
Join Date: Apr 2012
Posts: 1
Default [AS3] Random Frame from Radio Button

Hi Guys,

I'm a complete Flash newbie, all I've done is a few days of tutorials and stuff on the Internet. I'm knocking together a prototype for a University project.

I have a radio button list, and once a button is selected and submit is pressed it takes the user to a certain frame. Each radio button represents a different condition, and for the distance condition I want it to take the user to one of two frames; one which shows the animation close up, and one which shows it far away.

Before I attempted to have this button selection send the user to one of two frames, I had it working just sending them to the one. This is the code that I used:

ActionScript Code:
if (group.selection == distance) {         stop();                 submit.addEventListener(MouseEvent.CLICK, submit2Click);         function submit2Click(event:MouseEvent):void{         gotoAndPlay(32);     }     }

From what I've found on the Internet I believe that I need to generate random numbers and have this within an if statement. I've played about with various combinations with no luck. Below is what I currently have:

ActionScript Code:
if (group.selection == distance) {         stop();                 var n:Number = Math.round(Math.random()* 1+0);         trace(n);                 if (n == 1) {                      submit.addEventListener(MouseEvent.CLICK, submit2Click);         function submit2Click(event:MouseEvent):void{         gotoAndPlay(32);         }                 if (n == 0) {         submit.addEventListener(MouseEvent.CLICK, submit8Click);         function submit8Click(event:MouseEvent):void{         gotoAndPlay(501);         }         }     }     }

The trace shows me that the number generating is working, but when I click submit it always take me to frame 32 no matter what the number is. I'm unsure as to whether an if within an if is something which is going to work? I've been trying to get this to work for a couple of hours now and have run out of ideas. If any of you guys could give me some help then that would be great.

Thank you, Tom.
01matthewst is offline   Reply With Quote
Old 04-13-2012, 09:45 PM   #2
-:)lauri
Senior Member
 
Join Date: Aug 2008
Location: Helsinki, Finland
Posts: 1,184
Default

The code looks correct. So does the frame 501 exist? And if it does is after the frame something to play or should you use gotoAndStop() instead of gotoAndPlay()?

though I'd write the code maybe more like this:
ActionScript Code:
stop(); submit.addEventListener(MouseEvent.CLICK, gotoFrame); function gotoFrame(event:MouseEvent):void {     if(group.selection == distance)     {         var n:uint = uint(Math.random()* 2);         var frame:uint = n ? 32 : 501;         gotoAndPlay(frame);     } }

Last edited by -:)lauri; 04-13-2012 at 09:50 PM.
-:)lauri 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 Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:35 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.