11 Replies Latest reply on May 12, 2008 11:36 AM by CHAOS'|nc.

    Help with actionscript...

    damirahr
      Hi,
      I need some help including actionscript. Well I have one square on a stage, and i would like another square to: when I click the first square the second one goes from top to bottom (tween). Then, when i click first square second time, the second square goes back to its original position. I need this for kind of dropdown menu, which would go down (get visible) when user clicks on an arrow and go up when clicked another time...

      I tried to playe with On(press) event, but had no result....

      Thanks in advance!!!
        • 1. Re: Help with actionscript...
          Hi,

          It might be easier with rollover and rollout, let's say your second square has a y of 100 and you want it to go to 200 as an open submenu, you could do something like:

          • 2. Help with actionscript...
            damirahr Level 1
            Hi! Thanks for your reply.

            What I want:

            I have graphical button (gif) imported. I have one square set with alpha and five "menu" items written inside (like "about us", "what we do" etc...). These menu items are aligned horizontally inside this square. The square is not visible when flash is loaded, only gif. When users presses once on the giff, the menu along with items comes down (drops down). It stays down (visible) untill user again clicks on the gif, then the menu goes up (hides).
            I would really like this to work, but can't get it. I tried on(press) then making inside if condition but couldn't make it work. If anyone has an idea (or link) i would be very thankfull!

            Cheers

            Damir

            (p.s. I'm a real newbie in flash:)!
            • 3. Re: Help with actionscript...
              NecroSaint
              im not sure i understand your probem, are you just trying to make a button, so that when it is perssed a gif image moves down? and when itis pressed again it is moved up? thankyou
              • 4. Re: Help with actionscript...
                damirahr Level 1
                Ok... I'll try again:)

                I have a gif loaded that represents the button. When it is pressed first time square goes down. When it is pressed second time, the square goes up. Square is drawn in flash.

                Thanks a lot!
                • 5. Help with actionscript...
                  clbeech Level 3
                  what you are referring to is a 'drop-down menu' and there are many ways to construct one. higreg is on the right track using the Tween class as it is the simplest method to move an item using code - however if the gif is not 'part' or the 'entire' bg of the menu the onRollOver/Out methods will fail to achieve your goal - additionally there are other problems that arise when using a rollover handler on the parent container causing child handlers to not receive events.

                  But this is moot, since your objective sounds as though you have an 'external' button (gif) that you want to use as a 'toggle' switch - to control the movement of the menu. in this case you need to set up a conditional statement within the onPress handler of the button, and use a variable to determine the next action to take - open or close. The following code belong on the timeline - NOT attached to a button instance (eg -with a on(press) style handler) additionally you need instance names of 'menu_btn' on the button, and 'menu' on the square - it would go something like this:
                  • 6. Re: Help with actionscript...
                    damirahr Level 1
                    Thanks a lot for a reply...

                    I cant get your script working, because i'm a newbie... :)
                    About a conditional statement, i tried to do it with on(press) and if conditional statement. I even set up variable but the problem is, that I couldn't change variable state since, when script runs, variable alway get loaded first and then the state returns to its primary value.

                    About your code, could you have some time to explain me little detailed how to get it work? I understand if you don't want to hassle with it..:)

                    Thanks!

                    Damir.
                    • 7. Re: Help with actionscript...
                      clbeech Level 3
                      np - lol :)

                      it may be that you tried to place the code by 'attaching' it to an object - this code is meant to be used from the timeline. It is a 'best practice' to place all of your codes on a frame in the timeline rather than by using object attachment - in fact this had been eliminated in AS3 for that reason. in order to do so - create a new layer - call it 'actions' select a frame (the first one usually) then open the actions panel and enter the code above. placing your code on the timeline makes it easy to find, navigate paths and debug - this also may be the reason your variable had been getting reset.

                      also you need to have the instance name of 'menu_btn' on the button and 'menu' on the square in order for the above code to work properly.
                      • 8. Re: Help with actionscript...
                        damirahr Level 1
                        Hi there!
                        I must be stupid or something because i can't get it work :)
                        I have flash 8. This i what i do. I open a new document. Import my gif to stage, convert it to button and name it menu_btn. Then I draw a square, convert it into a graphic and name it menu. When i click on each of them i see in properties window that they are instance of menu and menu_btn. Then i create new layer and paste your code into the first frame...
                        when i test the movie, nothing happens upon click :)

                        I'm funny and annoying with this even to myself :)

                        Thanks for your help!
                        • 9. Re: Help with actionscript...
                          clbeech Level 3
                          lol! - you must convert the menu to an MC not a graphic - a graphic symbol cannot have an 'instance name' applied - and you need to have an instance name to control objects with code - it's being pointed at by the code as 'menu' - in fact both items must have 'instance names' - select the button on the stage - now look in the properties panel - on the left there is a input box that will say "<instance name>" type the name in there(ie. menu_btn) - convert the menu to a movieclip - and give it an instance name as well(ie. menu)
                          • 10. Re: Help with actionscript...
                            damirahr Level 1
                            Works perfectly!!!
                            Thank you a lot!

                            Have no doubt that I'll post another one when I get into a problem...!

                            Have a beer on me :) !

                            Cheers!
                            • 11. Re: Help with actionscript...
                              CHAOS'|nc. Level 1
                              lol. Your site's name really does justice on you man. You are a flash god!