Wednesday, August 26, 2009

XML Driven Advanced Horizintal Dropdown Menu with Tween effects in Actionscript 3

Visit this link to see the menu in action -:

http://www.fileden.com/files/2009/9/5/2565234/menu1.swf

First the contents of the menu must be put down in a XML file in the following format.

Each "main" tag gives the name of a main menu button in the "tag" tag and each "sub" tag gives the label of the sub menu buttons under it.
Let's name this file "myXML.xml". Remenber The flash(.fla) file and the XML file must be saved in the same folder.

Now open your flash file and hit Ctrl+Jto bring up the Properties Panel and set the background color as Black. Click OK and hit Ctrl+F8 to bring up the New Symbol window. Enter the name as mnMenu_mc and click on Advanced. Select Export for Actionscript. Click OK.

Select the Rectangle Primitive Tool and draw a small rectangle. This will be your Main Menu button. You can use any shape, size or color. But you have to make a not of the width of the button. Here i use a 65*20 rectangle with the fill color #0033CC. Now ceate a new layer on top of the present one and create a dynamic text field that almost fills up the button.


Select the text field and go to the Properties Panel and give it the instance name of text_txt. Now select both the button and the text field and open the Align Window and center both the objects.

Repeat the process and this time give the name as sbMenu_mc. You may choose a different shape or color if you like. The name of the text field will be the same as before.


This will be your sub menu button. Again make a note of the width of the button.

Thats all the graphics you need so now we script! Select the first frame of the only layer that sould be on your stage and hit F9 to bring up the Actions window. Copy and paste the following code. I hope the documentation is sufficient


Now hit Ctrl+Enter to test your movie! Mine looks something like this after i click on home but the actual coolness lies in the Tweens. Have fun!!

10 comments:

  1. Give me an email address i'll send you the .fla file. The site http://www.draeth.com/ is beautiful though.

    ReplyDelete
  2. hay its not working....

    Vini

    ReplyDelete
  3. Doesn't work. I pasted the code and got a lot of error messages.

    ReplyDelete
  4. didnt work for me... could u send me the actual .fla file to check what is wrong? i got 17 errors in syntax using your code.

    ReplyDelete
  5. can you please send me the fla file? tnx so much

    ReplyDelete
  6. my email address is iamotakuchan@gmail.com

    ReplyDelete
  7. Hi Subhrojit,

    Thanks for sharing the code. I pasted the code and it does not work.Will you be able to share the fla. My email id is mailtosuman@gmail.com

    Thanks
    Suman

    ReplyDelete
  8. Thanks a lot for sharing the code. I also pasted the code and it does not work. Would you pls send me the fla file. My email is baiweijie20.08@ichat.sp.edu.sg

    ReplyDelete
  9. About 18 syntax errors. Code needs a clean up, after that, should be fine.

    ReplyDelete