A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: [RESOLVED] [CS3]Trying to create "Rocker" style buttons

  1. #1
    Member
    Join Date
    Dec 2007
    Location
    Kirkland WA.
    Posts
    62

    resolved [RESOLVED] [CS3]Trying to create "Rocker" style buttons

    i tried this post in the Newbie section with no replys so i figuried i would try it here also

    Not sure if this is the place to post this or not but since I’m a newbie here it goes..., I’m trying to create some rocker buttons (for lack of a better name), where the top down position of the rocker button is on for something and the bottom position is on for something else, I'm trying to emulate an automotive type control panel. Also I want to have the user turn a knob to increase and decrease animated heat. Can anybody point me in the right direction for a tutorial or?

    Thank you in advance for your help

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    a 'rocker' style button.. as in a 'toggle' swtich?

    this could just be a two frame movieClip that you jump to frame 1 (switch up) or frame 2 (switch down) on each press..

  3. #3
    Member
    Join Date
    Dec 2007
    Location
    Kirkland WA.
    Posts
    62
    Yes a toggle switch.
    The 2 frame style is what I’m working on now. I'm new to flash so I was having trouble wrapping my head around the action script part of it. i should have used director to create my interface (just because I’m more familiar with it)

    Thank you for the reply, hopefully i can figure it out

  4. #4
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    well it depends on what you want to do really...
    but to switch the graphic (2 frame movieClip) from the up to down position..

    all you need is a toggleClip.play(); action.. since it only has 2 frames.. it can only toggle between the two..

    to assign CODE to your positions you wold have to use a variable or boolean and check its state and do your actions accordingly.

    a two stage IF statement would work..but its faster to use the TERNARY operator (yeah i had to ask too) LOL

    PHP Code:
    = (== 1) ? 10 20
    the above says:

    variable Y is equal to (then checks to see if variable X is equal to 1) and if X IS equal to 1,... then Y is assigned the value of 10 if variable X does NOT equal 1,...then Y is assigned the value of 20.


    this is the same as doing this: (longer way)
    PHP Code:
    if (== 1){ 
        
    10;
    }else{
        
    20;

    so for your project maybe something like this:

    PHP Code:
    toggleClip.onRelease = function() {
        
    this.play();
        
    //toggle = (toggleOn = !toggleOn) ? trace("this") : trace("that");
        
    toggle = (toggleOn = !toggleOn) ? onFunction() : offFunction();
    };

    function 
    onFunction(){
        
    trace("TOGGLE IS ON!");
    }
    function 
    offFunction(){
        
    trace("TOGGLE IS OFF!");

    with toggleClip being the instance name of your 2 frame movieClip on your stage.. and this code in frame 1 of the main timeline...




    hope this helps..

  5. #5
    Member
    Join Date
    Dec 2007
    Location
    Kirkland WA.
    Posts
    62
    Will this same type of thing work for a 3 position switch?

    another question (this one is stupid)
    i'm trying to do a simple ".gotoAndStop(10);" what goes in frount of it. i thought it was the name of my flash movie "Switch_Air.fla" but i get a "1120: Access of undefined property Switch_Air."

    it is something easy that im missing, sorry for the stupid question and thank you for the help on the toggle.

  6. #6
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    no..it wont work.. you'll need to add some logic that decides when its on..when its off.. and when its supposed to be ON then..

    and I dont think the ternary operator will work either... just a longer if/if else/else type statement then...


    for ANY gotoAndPlay() statement the name of the movieClip you want to control goes in front..

    so if you have a movieClip on your stage called: circleClip

    and you wanted to go to frame 10 of THAT movieClip.. you would use:

    circleClip.gotoAndPlay(10);

    if you want to do the MAIN time line you just use:

    gotoAndPlay(10); (no . in front)

    or just say _root.gotoAndPlay(10);

    _root. means the MAIN timeline..

  7. #7
    Member
    Join Date
    Dec 2007
    Location
    Kirkland WA.
    Posts
    62
    ok that worked
    thank you very much for the help, have a good day

  8. #8
    Member
    Join Date
    Dec 2007
    Location
    Kirkland WA.
    Posts
    62
    Whisper can i ask you a follow up question?

    I'm trying the gotoAndStop between the 2 frames like we talked about but.......im not sure if that is what i need maybe i need some Kind of "on event" go to and stop. this is what i have

    frame 1:

    gotoAndStop(10)

    function clickButton(evt:Event):void{
    trace("the " + evt.target.name + " button was clicked");

    }
    Toggle_up.addEventListener(MouseEvent.CLICK,clickB utton);


    frame 10:

    Toggle_up_bottom.addEventListener(MouseEvent.CLICK ,clickButton);



    with "Toggle_up" as the button in the first frame thru 9 and "Toggle_up_down" as the button 10 thru 20

    i tried the gotoAndStop it worked good for the first frame but when i added it to the 10th frame it did nothing... it would not even complile

    is there such a thing as on event go to and stop?

    thank you again for your time

  9. #9

  10. #10
    Member
    Join Date
    Dec 2007
    Location
    Kirkland WA.
    Posts
    62
    i creted 2 seperate halfs of the same button (top, bottom) and one in frame 1 the other in frame 10 with the other half of the button as a graphic on each of the corrisponding layers. that way the buttons look correct and when they are in the down position on either the top or the bottom they will not have any button look functionality (mouse over change). your toggleClip way is much better but i'm so new to flash i could not figure it out.

    Am i just trying to do it a way that will not work?

  11. #11
    Member
    Join Date
    Dec 2007
    Location
    Kirkland WA.
    Posts
    62

    [CS3][resolved]

    Resolved thank you

  12. #12
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    as pointed out by fellow memeber MyFirendIsATaco

    there was no assignment of the toggle var.. it will always be NULL..

    so you do this:
    PHP Code:
    toggleClip.onRelease = function() {
        
    //toggle = (toggleOn = !toggleOn) ? trace("this") : trace("that");
        
    toggle = (toggleOn = !toggleOn) ? onFunction() : offFunction();
        
    //assign toggle a var
        
    toggle toggleOn;
        
    //trace it out
        
    trace("TOGGLE: "+toggleOn);
        
    };
    function 
    onFunction() {
        
    trace("TOGGLE IS ON!");
    }
    function 
    offFunction() {
        
    trace("TOGGLE IS OFF!");

    assign toggle the value of toggleOn..

    or just remove that var all together..

    PHP Code:
    toggleClip.onRelease = function() {
            (
    toggleOn = !toggleOn) ? onFunction() : offFunction();
        
    //trace it out
        
    trace("TOGGLE VALUE: "+toggleOn);
        
    };
    function 
    onFunction() {
        
    trace("TOGGLE IS ON!");
    }
    function 
    offFunction() {
        
    trace("TOGGLE IS OFF!");

    or this way:

    PHP Code:
    function onFunction():Void {
        
    trace("on");
    }
    function 
    offFunction():Void {
        
    trace("off");
    }
    toggleClip.toggleOn false;
    toggleClip.onRelease = function():Void  {
        (
    this.toggleOn = !this.toggleOn) ? onFunction() : offFunction();
        
    }; 
    keeping scope INSIDE that button..

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