Use of Radio Buttons in Actionscript 2.0

I need some help in understanding why my code doesn't work.

Page 1 of 1

11 Replies - 18972 Views - Last Post: 17 December 2007 - 11:28 AM

#1 lidusca  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 14-December 07

Use of Radio Buttons in Actionscript 2.0

Posted 14 December 2007 - 10:49 PM

I have two sets of radio buttons on the stage. I'm trying to change a variable to the selection a user makes. I placed trace stmts within the listener function, because I think that the function doesn't even get called. When I run the swf file, you could actually select within a group with no problem. Just that the variable never gets changed. I don't seem to locate the problem. Here is my code for one group of buttons called timeRateGroup:

var flashBListener:Object = new Object();
flashBListener.click = function (evt:Object) {
trace("the selected radio button is: " +evt.target.selection);
SharedData.timingSession = evt.target.selection.data;
}
bkgrd.timeRateGroup.addEventListener("click", flashBListener);

thanks!

This post has been edited by lidusca: 14 December 2007 - 10:50 PM


Is This A Good Question/Topic? 1

Replies To: Use of Radio Buttons in Actionscript 2.0

#2 DilutedImage  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 646
  • Joined: 20-November 06

Re: Use of Radio Buttons in Actionscript 2.0

Posted 14 December 2007 - 10:56 PM

Does the trace work?
Was This Post Helpful? 0
  • +
  • -

#3 lidusca  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 14-December 07

Re: Use of Radio Buttons in Actionscript 2.0

Posted 14 December 2007 - 11:51 PM

View PostDilutedImage, on 14 Dec, 2007 - 10:56 PM, said:

Does the trace work?


No, the trace doesn't work! As I mentioned before I have a movie clip which has a bkgrd on it with couple of radio buttons, two groups to be precise. All the code for this movie clip is in the .as file. Here is the entire file. As you will see I was trying two different methods of getting the click to update my global variable.

--------------------------------------------------------------------------------

class SettingsSession extends MusicTheoryPage {
// instance variables
private var bkgrdName:String = "settings_bkgrd_mc";

function rbListener(evtObj:Object) {
trace("in here now");
trace("the selected radio button is 1 : " +evtObj.selection.data);
SharedData.whatQuestions = evtObj.selection.data;
}


/********************************************************************************
* bringUpPage brings up the Opening page
********************************************************************************/
public function bringUpPage() {
var owner:Object = this;

trace("SS: In bringUpPage()");

SharedData.currentSession = SharedData.SETTINGS_SESSION;


bkgrd.presentGroup.addEventListener("click", rbListener);
trace("after present questions, selection: " + SharedData.whatQuestions);


var flashBListener:Object = new Object();
flashBListener.click = function (evt:Object) {
trace("the selected radio button is: " +evt.target.selection);
SharedData.timingSession = evt.target.selection.data;
}
bkgrd.timeRateGroup.addEventListener("click", flashBListener);
trace("after timing session, selection: " + SharedData.timingSession);

trace("SS: exiting bringUpPage()");
} // end bringUpPage()

} // end SettingsSession class

-----------------------------------------------------------------------------------------
Was This Post Helpful? 0
  • +
  • -

#4 DilutedImage  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 646
  • Joined: 20-November 06

Re: Use of Radio Buttons in Actionscript 2.0

Posted 15 December 2007 - 12:51 AM

You've defined rbListener as a function, and then called it as a listener object. Instead of this: function rbListener(evtObj:Object) {
try this:
var rbListener:Object = new Object();
rbListener.click = function(evtObj:Object) {


Calling a function as an event listener will work in ActionScript 3, but not in 2.

And once inside that function, you'll probably want to reference "evtObj.target.selection.data", rather than "evtObj.selection.data".

This post has been edited by DilutedImage: 15 December 2007 - 12:51 AM

Was This Post Helpful? 0
  • +
  • -

#5 lidusca  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 14-December 07

Re: Use of Radio Buttons in Actionscript 2.0

Posted 15 December 2007 - 01:33 AM

View PostDilutedImage, on 15 Dec, 2007 - 12:51 AM, said:

You've defined rbListener as a function, and then called it as a listener object. Instead of this: function rbListener(evtObj:Object) {
try this:
var rbListener:Object = new Object();
rbListener.click = function(evtObj:Object) {


Calling a function as an event listener will work in ActionScript 3, but not in 2.

And once inside that function, you'll probably want to reference "evtObj.target.selection.data", rather than "evtObj.selection.data".



That's the technique I'm using for the second set of buttons. I took out the code for the first set of buttons, saved the swf and published it again. Tried it again for the second set of
buttons and still doesn't work. I'm having the same problem with a list component. I did more reading and I found out that I have to define the component instances in Actions layer on the movie clip that contains them. So I did that, too. It looks something like this:
import mx.controls.*;
var howToBtn1:Button;
var howToBtn2:Button;
var fastBtn:Button;
var mediumBtn:Button;
var slowBtn:Button;

And the .as file contains the rest of the code.
I need to mention that I'm running Flash 8 Educational version if this will make any difference.
Was This Post Helpful? 0
  • +
  • -

#6 DilutedImage  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 646
  • Joined: 20-November 06

Re: Use of Radio Buttons in Actionscript 2.0

Posted 15 December 2007 - 03:37 AM

Can you just ZIP and attach the file? It'd be a whole lot easier than troubleshooting code that you're not even using.
Was This Post Helpful? 0
  • +
  • -

#7 lidusca  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 14-December 07

Re: Use of Radio Buttons in Actionscript 2.0

Posted 15 December 2007 - 01:08 PM

View PostDilutedImage, on 15 Dec, 2007 - 03:37 AM, said:

Can you just ZIP and attach the file? It'd be a whole lot easier than troubleshooting code that you're not even using.



All right, I'm attaching the zip file which has the .fla file and the SettingsSession.as file where the buttons code is. Other files needed are also in there. Settings Session is the page that has the problem. There is a Settings folder in the Library which has the background image in it. Hope this is what you request. Thanks a lot for looking into it!

Lidia


P.S.

I did attach the zip file but I don't see it. Where did it go?

This post has been edited by lidusca: 15 December 2007 - 01:13 PM

Was This Post Helpful? 0
  • +
  • -

#8 DilutedImage  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 646
  • Joined: 20-November 06

Re: Use of Radio Buttons in Actionscript 2.0

Posted 15 December 2007 - 06:26 PM

No idea what happened to it. Try again.
Was This Post Helpful? 0
  • +
  • -

#9 lidusca  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 14-December 07

Re: Use of Radio Buttons in Actionscript 2.0

Posted 15 December 2007 - 10:39 PM

View PostDilutedImage, on 15 Dec, 2007 - 06:26 PM, said:

No idea what happened to it. Try again.



Is it because it says here that Global Space Left: 1000K and my zip file is bigger than that. It is a little over 2Meg. And if that's the problem why doesn't it warn you that the file wasn't attached. Anyway, I need to chop my .fla file down in order to be attached. I'll send it when I'm done.

All right, I managed to cut down the size of the .fla file having only the Settings Session in there. The trace stmts should display the changes when the buttons get selected, but they always display the default and never show that the listener was activated.

Here is the zip file. Again, thanks so much for helping.

LidiaAttached File  FlashProblem.zip (368.11K)
Number of downloads: 763

This post has been edited by lidusca: 15 December 2007 - 11:06 PM

Was This Post Helpful? 0
  • +
  • -

#10 DilutedImage  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 646
  • Joined: 20-November 06

Re: Use of Radio Buttons in Actionscript 2.0

Posted 16 December 2007 - 12:48 PM

The value of bkgrd isn't being passed to your SettingsSession. It traces undefined. Once you've created an instance of SettingSession, you'll need to pass the value into it.
Was This Post Helpful? 0
  • +
  • -

#11 lidusca  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 14-December 07

Re: Use of Radio Buttons in Actionscript 2.0

Posted 16 December 2007 - 03:52 PM

View PostDilutedImage, on 16 Dec, 2007 - 12:48 PM, said:

The value of bkgrd isn't being passed to your SettingsSession. It traces undefined. Once you've created an instance of SettingSession, you'll need to pass the value into it.



How can that be? When I ran it from my system the tracing works fine. It comes out as :
_level0.settings_bkgrd_mc. The background variable is set in MusicTheoryPage.as and the name is set in Settings.as file. I unzipped the file I uploaded to your server and tested the .swf. It works fine. Here is the SettingsSession.as file again.Attached File  SettingsSession.zip (710bytes)
Number of downloads: 202


==========================================================
All right, I've done a little more testing and this is what I found:

If I take the code that is in SettingsSession.as file and attach it to the Timeline of Settings Session background movie clip (settings_bkgrd_mc) Frame 1, the code works like a charm. < "bkgrd." is taken out since the Timeline is already the background timeline!>

But, if the same code is called from SettingsSession.as it fails. The reason it fails is because the buttons and the button group name is not recognized. Even though I named the button instances and I gave them a group name from within the SettingsSession.as file, they are "undefined". Why? I have no clue. In looking thru the Flash Help that comes with Flash software, in all their examples they either place the code on the same timeline with the buttons, or if placed in an Actionscript file (like I do) they create class object of type "RadioButton", assign a group to it and then use that group name with the listener. I guess I'm using the group name that I assigned to the buttons via the button instances (which apparently is not recognized) -- I did not dynamically create the buttons via Actionscript! The buttons have already been created, I just need to manipulate them from Actionscript file!

Does anybody know why there is a difference. Even in Flash Help, they mention using the group name via button instance name. Very confused!

This post has been edited by lidusca: 16 December 2007 - 07:03 PM

Was This Post Helpful? 0
  • +
  • -

#12 DilutedImage  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 646
  • Joined: 20-November 06

Re: Use of Radio Buttons in Actionscript 2.0

Posted 17 December 2007 - 11:28 AM

Interesting; I couldn't get a trace. I'll try again though. And there shouldn't be a difference in how the component is used. Often there are additional parameters than need to be setup when adding components via ActionScript, but RadioButtons aren't one of the ones that work differently. Looking at the code, and can't find any error in how you are using them. You've properly set their group names in the parameters, and properly scripted the event listeners/handlers. I'm confident it's likely just a pathing issue. I'll dig deeper into this afternoon, when I have a little free time.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1