A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: radiobutton between frames

  1. #1
    Junior Member
    Join Date
    Mar 2006
    Posts
    8

    radiobutton between frames

    Newbie using radiobuttons - everything works ok. Using it in a slide presentation that goes frame by frame using buttons and gotoandstop function.

    When I go forward and back a frame any selections made on the radiobuttons are lots. Is there an easy way to save these so they are not lost when i change frames?

    Thanks
    beaco

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Here is a simple script for 2 radiobuttons:
    PHP Code:
    import mx.controls.RadioButton;
    var 
    radio1:RadioButton;
    var 
    radio2:RadioButton;
    var 
    id:MovieClip;
    radio1.label "number 1";
    radio2.label "number 2";
    var 
    myListener:Object = new Object ();
    myListener.click = function (obj:Object) {
        
    id obj.target;
    };
    radio1.addEventListener ("click"myListener);
    radio2.addEventListener ("click"myListener);
    id.selected true
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Junior Member
    Join Date
    Mar 2006
    Posts
    8
    i think i just need the part of the code shown below as I have already created the radio buttons using the flash GUI.

    Does this mean that for each set of radiobuttons i need a unique mylistener and id object?

    var id:MovieClip;
    var myListener:Object = new Object ();
    myListener.click = function (obj:Object) {
    id = obj.target;
    };
    radio1.addEventListener ("click", myListener);
    radio2.addEventListener ("click", myListener);
    id.selected = true;

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You need one listener for all radiobuttons. If you have several with a similar name like radio1, radio2 etc you can use a for loop.

    var numButs:Number = 6;
    for (var count=1;count<=numButs;count++){
    this["radio"+count].addEventListener ("click", myListener);
    }
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Junior Member
    Join Date
    Mar 2006
    Posts
    8
    You mean I need a listener for each set (group) of radiobuttons.

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    That is correct, but not for each radiobutton.
    - The right of the People to create Flash movies shall not be infringed. -

  7. #7
    Junior Member
    Join Date
    Mar 2006
    Posts
    8
    Can I do a similar thing with input textboxes so they don't lose their contents?

  8. #8
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You can. Check the event handlers in the flash help files for textinput. I think the handler is change instead of click, but make it sure.
    - The right of the People to create Flash movies shall not be infringed. -

  9. #9
    Junior Member
    Join Date
    Mar 2006
    Posts
    8
    Thanks for all your help. This is my first time using flash so its a bit quirky.

    If I want to access id._name from a different frame can I declare it as global or something?

    I was reading things that suggested declaring it as this.id:movieclip or _global.id:movieclip but i get syntax errors. Any help is appreciated.

    Thanks

  10. #10
    Junior Member
    Join Date
    Mar 2006
    Posts
    8
    Also the above code for radiobuttons doesn't work when using the tab key to make selections. Is there another methods like group.selected.changed() or similar to activate the change.

  11. #11
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    1. key listener events are triggered differently. Check the flash help files.
    2. this.id:movieclip is the wrong syntax. First you need to declare the var and add the datatype:
    var id:MovieClip;
    this.id = id;

    3. Do not use _global. It is not recommended, because your var may interfere with other code and then debugging becomes difficult. In your case it is simple. Whenever you refer to id use the path, which would be this or _root or _level0.
    - The right of the People to create Flash movies shall not be infringed. -

  12. #12
    Junior Member
    Join Date
    Mar 2006
    Posts
    8
    custType is defined on frame 3.

    I still can't find a way to access custType._name from frame 6. I have tried this. and _parent. and _level0. and _root. and this._parent everything is returned as undefined.

    Any ideas/.

  13. #13
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You have to show coding, if anybody should help you. We cannot guess what custType is or anything else.
    - The right of the People to create Flash movies shall not be infringed. -

  14. #14
    Junior Member
    Join Date
    Mar 2006
    Posts
    8
    var custType:MovieClip;
    var custTypeListener:Object = new Object ();
    custTypeListener.focusIn = function (obj:Object) {
    custType = obj.target;
    };
    busCustomer.addEventListener("focusIn", custTypeListener);
    indCustomer.addEventListener ("focusIn", custTypeListener);
    custType.selected = true;

    as above - Is there a way of accessing custType.name from other frames?

    Notel busCustomer and indCustomer and instances of the radiobutton component.

  15. #15
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Your script works for me. When you say "frame", which frame or frames do you mean?
    - The right of the People to create Flash movies shall not be infringed. -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center