actionscript fails why?

  • davidgraham18
  • Born
  • Born
  • davidgraham18
  • Posts: 2

Post 3+ Months Ago

can you spot what is wrong with my code
I have 3 checkboxes on scene 1 of the movie. When one is clicked the other 2
should be cleared. The initial value of the first checkbox (instance name is
biking) is set to true and the other 2 (walking and running) are set to
false.
At the moment all 3 can be checked - this should not be allowed by my code -
the code below is in an action layer frame 1 and the checkboxes have a
change handler set (called checkChanged, checkChanged2 and checkChanged3).
Points of interest I have noticed are:
1. The trace bit fails to execute if its put inside the if conditional.
2. I can get the trace to work inside the if conditional if I change the
double equals to a single equals

[as]
function checkChanged(){
trace("check box 1 changed");
if(this.selected == true){
_root.running.selected = false;
_root.walking.selected = false;
}
}

function checkChanged2(){
trace("check box 2 changed");
if(this.selected == true){
_root.biking.selected = false;
_root.walking.selected = false;
}
}

function checkChanged3(){
trace("check box 3 changed");
if(this.selected == true){
_root.biking.selected = false;
_root.running.selected = false;
}
}

[/as]

I really would like some light shed on this if you can please. Just a novice
though so please spell out in idiot proof language whats going on and how do
I get it to work. I know radio buttons is a better choice but this is a
learning exercise and a challenge I have set myself. I use Flash MX
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • [SteF]
  • Beginner
  • Beginner
  • [SteF]
  • Posts: 58
  • Loc: Belgium

Post 3+ Months Ago

did you add an event-handler? you have 3 functions, but your code what's listed here doesn't call any of this functions
i think it should work this way:

biking.onPress = function() { //here's the handler
trace("check box 1 changed");
if(this.selected == false){ /*change that true to false because this block of code will happen before that the selected property is changed*/
_root.running.selected = false;
_root.walking.selected = false;
}
}

running.onPress = function() {
trace("check box 2 changed");
if(this.selected == false){
_root.biking.selected = false;
_root.walking.selected = false;
}
}

walking.onPress = function () {
trace("check box 3 changed");
if(this.selected == false){
_root.biking.selected = false;
_root.running.selected = false;
}
}
  • davidgraham18
  • Born
  • Born
  • davidgraham18
  • Posts: 2

Post 3+ Months Ago

Thanks - much to learn from this code.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 16 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.