A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Actionscript rotate If Statement

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    17

    Actionscript rotate If Statement

    I have 2 buttons (buttonIncrease and buttonDecrease). I also have two switches. When the switches are clicked on, one movie clip symbols visibility becomes false while the other visibility becomes true to get the "on and off" effect.

    buttonIncrease code

    buttonIncrease.onPress = function()
    {
    gauge.onEnterFrame = function()
    {
    if(this._rotation == 180)
    {
    delete this.onEnterFrame;
    return;
    }
    this._rotation += 1;

    }
    }

    buttonDecrease code

    buttonDecrease.onPress = function()
    {
    gauge.onEnterFrame = function()
    {
    if(this._rotation == 0)
    {
    delete this.onEnterFrame;
    return;
    }
    this._rotation -= 1;

    }
    }



    what i need is an if statement that looks something like this

    if(this._rotation == 30 && switchOn._visible == true && lightOn._visible == true){

    the gauge starts to increase once reached 30 degrees and both switches are on

    }

    hope thats understandable :P

    thanks!

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Not sure what you're asking. The first part you reference a simulated on/off switch, the second part you're asking for an if statement that matches the if statement you provided. If you want to check the rotation and the visibility of two object, then you're if statement is correct.

    Am I missing something?
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  3. #3
    Junior Member
    Join Date
    Jun 2009
    Posts
    17
    sorry i thought it would be hard to understand...

    so pretty much if 2 switches are visible and the gauge is in the 30 degrees position i want the gauge to start rotating CW.

    for example, if my 2 switches are visible and i press the buttonDecrease and the gauge decreases CCW, once it hits that 30 degrees mark it will automatically start going CW because the 2 switches are visible and, like i said, the gauge is 30 degrees.

    hope that helps :P

  4. #4
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813

    Improve the If statement

    Okay, I think I got it. Try something like this (you actually have it just place it within the button):
    PHP Code:
    buttonDecrease.onPress = function()
    {
        
    gauge.onEnterFrame = function()
        {
            if(
    this._rotation == 0)
            {
                
    delete this.onEnterFrame;
                return;
            }
            else if(
    this._rotation == 30 && switchOn._visible && lightOn._visible)
            {
                
    this._rotation += 1;
            }
            else
            {
                
    this._rotation -= 1;
            }
         }

    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  5. #5
    Junior Member
    Join Date
    Jun 2009
    Posts
    17
    hmm... i cant seem to get it working. attached is the my program. if you can, could you take a look at it? you have the idea now :P

    if you need me to explain further, please let me know.

    thanks for the help!
    Attached Files Attached Files

  6. #6
    Junior Member
    Join Date
    Jun 2009
    Posts
    17
    hey never mind it works lol.. but there is one problem..
    when the gauge reaches the 30 degrees mark, the gauge itself starts to kinda vibrate lol.. like it tries to go CW but its still being pushed CCW. its probaby like one little piece of code :P

  7. #7
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    I'm not seeing the vibration problem.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  8. #8
    Junior Member
    Join Date
    Jun 2009
    Posts
    17
    I have seemed to fix the vibration problem. Now it just wont increase. It hits the 30 mark and stays there. Is there any other bit of code to fix it? or something i can try?

    thanks

  9. #9
    Junior Member
    Join Date
    Jun 2009
    Posts
    17
    actually it still vibrates.. you have to zoom in while its playing.

  10. #10
    Junior Member
    Join Date
    Jun 2009
    Posts
    17
    ok so i think i found the problem.

    when using this:

    buttonDecrease.onPress = function()
    {
    gauge.onEnterFrame = function()
    {
    if(this._rotation == 0)
    {
    delete this.onEnterFrame;
    return;
    }
    else if(this._rotation == 30 && switchOn._visible && lightOn._visible)
    {
    this._rotation += 1;
    }
    else
    {
    this._rotation -= 1;
    }
    }
    }



    the rotation stops at 30 because of the if statement BUT while its increasing by 1 like its told to do, the else statement at the end where it wants to -1 interfers and it creates this vibration because its like fighting to increase and decrease at the same time.

  11. #11
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Maybe you can clear us some of the conditionals. When should it stop at 30? What are the conditions to start and stop and what direction.

    PHP Code:
    buttonDecrease.onPress = function() 

        
    gauge.onEnterFrame = function() 
        { 
            if(
    this._rotation == 0
            { 
                
    delete this.onEnterFrame
                return; 
            } 
            else if(
    this._rotation == 30 && t1._visible==true && t2._visible==true
            { 
                
    this._rotation += 1
            }
            else if(
    this._rotation 30 && t1._visible == false && t2._visible == false)
            { 
                
    this._rotation -= 1
            } 
            } 
         } 
    You can try a additional conditional statements like the one above.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  12. #12
    Junior Member
    Join Date
    Jun 2009
    Posts
    17
    thank you for your reply. this is the actual code im working with right now and maybe it will be understandable

    PHP Code:
    Air_Receiver_Drain_Valve_1.onPress = function() {
        
    gauge.onEnterFrame = function() {
            if (
    this._rotation == 0) {
                
    delete this.onEnterFrame;
                
    _root.air_pressure_2._visible false;
                
    _root.air_pressure_2._visible false;
                
    _root.Spinning_Wheels_1._visible false;
                
    _root.Spinning_Wheels_2._visible false;
                
    _root.Spinning_Wheels_1_NotMoving._visible true;
                
    _root.Spinning_Wheels_1_NotMoving._visible true;
                return;
            } else if (
    this._rotation==30 && Auto_Select._visible == true && Air_Receiver_Drain_Valve_2._visible == true && button_off_1._visible == true) {
                
    this._rotation += 1;
            } else {
                
    this._rotation -= 1;
                
    gotoAndPlay(2);
                
    _root.air_pressure_2._visible true;
            }
        };
    }; 
    now when the gauge (which is moving CCW) hits the 30 mark and auto select and reciever drain are true, the gauge should automatically start moving CW.

    the problem is is when the gauge hits the 30 mark and auto select and reciever drain are true, the gauge stops at 30 and it tries to go CW (which the else if statement states) but the else statment at the end is telling it to go CCW so it kind of fights itself and creats a vibration kinda thing.

    i just want the gauge to go CW when gauge is at 30 and the objects visibility are true.

Tags for this Thread

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