942,956 Members | Top Members by Rank

Ad:
0

Flash: create a simple menu

by on Mar 20th, 2007
In this tutorial you will learn how to create a simple menu using Flash, while the menu items themselves will be imported from an XML file called menu.xml.

1. Start by creating a new flash document which can be called anything you like as long as the size is set to 550 x 80 px and the frame rate to 24fps in the property panel as shown below. If you can’t see this, click anywhere on the editing area and press CTRL+F3.

Name:  flashmenu001.jpg
Views: 10360
Size:  23.0 KB


2. Next, create a rounded rectangle sized 135 x 40.6px but of any radius, the one shown below is 10 px.

Name:  flashmenu002.jpg
Views: 3214
Size:  15.8 KB


3. Now make two layers, the first being ‘actions’ and the second ‘content’ as shown, and then put the rounded rectangle into the contents layer.

Name:  flashmenu003.jpg
Views: 10112
Size:  25.8 KB


4. Select the text tool and insert text with a label of ‘label’.

Name:  flashmenu004.jpg
Views: 10088
Size:  13.5 KB


5. Set the properties of this text label so that it looks similar to the illustration. The Dynamic Text setting is used so you the label can be changed at runtime.

Name:  flashmenu005.jpg
Views: 3280
Size:  56.1 KB


6. Select both text and rectangle, then press F8. You will see the following window, set the properties similar to this and give it an instance name of “old”.

Name:  flashmenu006.jpg
Views: 10196
Size:  29.8 KB


7. Convert this to a symbol by pressing F8 and setting name to ‘button_’ while giving it an instance name “label” and now select “button” as shown.

Name:  flashmenu007.jpg
Views: 10105
Size:  15.1 KB


8. Add two layers, one “text” and another “button” and then put text into the text layer and your button in the button layer. Convert text to a movie clip by pressing F8 and name it as text. Set the instance name to “label” and add the key frames as shown, selecting key frame 1 from the button layer and pressing F9. Add action script stop(); and then do same with layer 15.

Name:  flashmenu008.jpg
Views: 3180
Size:  56.4 KB


9. Now select key frame 15 and then select the rectangle. Set the Color property to Tint, and choose whatever color you want but with an alpha percent of 50%. You will find this option at the right hand side of the color picker when collapsed.

Name:  flashmenu009.jpg
Views: 10041
Size:  40.1 KB


10. Repeat step 9, but with the text label.

11. Next, you need to add some ‘motion tween’ by right clicking between the keyframe ‘1 and 15’ and ‘15 and 30’ of both layers one by one and selecting Create Motion Tween.

Name:  flashmenu010.jpg
Views: 10005
Size:  76.1 KB


12. Open the Library window by pressing F11 and then right click on the ‘button_’ item. Select linkage and then set properties as given below, checking the export for ActionScript and export in first frame boxes. This helps you to access this object during runtime dynamically.

Name:  flashmenu011.jpg
Views: 10204
Size:  40.6 KB


13. In the directory where you have saved this flash document, create an xml file as follows…

xml Syntax (Toggle Plain Text)
  1. <xml width="80" horizontal="true">
  2.  
  3. <menu>
  4. <name>Cover</name>
  5. <link>http://www.geocities.com/coolvish91</link>
  6. <target>_self</target>
  7.  
  8. </menu>
  9.  
  10. <menu>
  11. <name>Introduction</name>
  12. <link>http://www.geocities.com</link>
  13. <target>fr1</target>
  14. </menu>
  15.  
  16. <menu>
  17. <name>Formatting</name>
  18. <link>http://www.yahoo.com</link>
  19. <target>_self</target>
  20.  
  21. </menu>
  22.  
  23. <menu>
  24. <name>Tables</name>
  25. <link>http://www.msn.com</link>
  26. <target>_blank</target>
  27. </menu>
  28.  
  29. <menu>
  30. <name>Frames</name>
  31. <link>http://www.adobe.com</link>
  32. <target>_parent</target>
  33. </menu>
  34.  
  35. <menu>
  36. <name>Forms</name>
  37. <link>http://www.microsoft.com</link>
  38. <target>_parent</target>
  39.  
  40. </menu>
  41. </xml>

14. Now go back to scene one and in the actions layer first keyframe press F9 to open the action panel and then insert the following code:

 /*
       SIMPLE FLASH-XML MENU
       VISHESH YADAV
       12/05/2005
  */
 
  fscommand("allowscale", "false");
 
  function xmlLoaded(loaded) {
       if (loaded) {
            now._visible = false;
            xmlNode = xmlData.firstChild;
            total = xmlNode.childNodes.length;
            name = [];
            link = [];
            Target = [];
            mcWidth = xmlNode.attributes.width;
            mcHori = xmlNode.attributes.horizontal;
            for (i=0; i<total; i++) {
                name[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
                link[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
                Target[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
                _root.createEmptyMovieClip("_button", i);
                _root._button.attachMovie("button", button+i, i);
            }
            // end of for
       } else {
            now._visible = true;
            now._width = _root._width-20
            now._height=(1/7.74)*now._width
       }
       // end if
  }
  // End of the function
  now._visible = false;
  xmlData = new XML();
  xmlData.ignoreWhite = true;
  xmlData.load("menu.xml");
  xmlData.onLoad = xmlLoaded;

15. Staying in scene 1, select ‘button_’ and then press F9 to open the action panel again and insert the following code:

onClipEvent (load) {
    deep = _parent.getDepth();
    getWidth = _parent._parent._parent.mcWidth;
    getHori = _parent._parent._parent.mcHori;
    if (getHori == "true") {
        this._width = getWidth;
        this._height = 0.300000*getWidth;
        this._x = 10+deep*(this._width+5);
        this._y = 17;
    } else {
        this._width = getWidth;
        this._height = 0.300000*getWidth;
        this._x = 10;
        this._y = 20+deep*(this._height+5);
    }
    getLink = _parent._parent._parent.link[deep];
    getlabel = _parent._parent._parent.name[deep];
    getTarget = _parent._parent._parent.Target[deep];
    this.label.label.text = getlabel;
}
on (release) {
    getURL(getLink, getTarget);
}
on (rollOver) {
    this.gotoAndPlay(2);
}
on (rollOut) {
    this.gotoAndPlay(11);
}


16. You can now delete the button if you like and it is stored in the library, available for use anytime. However, you should insert a movie clip which will be shown if your XML file is not found, with an instance name of ‘now’ – it should look something like this:

Name:  flashmenu012.jpg
Views: 10271
Size:  21.2 KB


17. Finally, press CTRL+Enter and you should see your finished Flash menu output.
Last edited by cscgal; May 13th, 2007 at 11:12 pm.
Similar Threads
Comments on this Tutorial
Mar 26th, 2007
0

Re: Flash-XML Menu

Here's how it should look. This zip files includes the FLA, SWF and HTML file http://vishesh.datadiri.net/FILES/FLASH_XML_MENU.ZIP
Nearly a Posting Virtuoso
vishesh is offline Offline
1,362 posts
since Oct 2006
Mar 30th, 2007
1

Re: Flash-XML Menu

I'm attaching this file as an attached .zip. From now on, do that instead of pointing users to off-site files, because what inevitably happens is a few months down the line you take them off of your server for whatever reason, and then this tutorial gets broken.
Attached Files
File Type: zip FLASH_XML_MENU.ZIP (19.1 KB, 2485 views)
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Jun 13th, 2008
0

Re: Flash-XML Menu

It would be great to have this menu available for Actionscript 3.0!!

Thanks!
Newbie Poster
physicsworld is offline Offline
1 posts
since Jun 2008
Oct 13th, 2008
0

Re: Flash-XML Menu

good tutorial thanx ...
Last edited by cscgal; Sep 4th, 2009 at 5:44 pm. Reason: Plug snipped
Newbie Poster
sjsconsultants is offline Offline
3 posts
since Aug 2008
Aug 7th, 2009
0

Re: Flash-XML Menu

Hi
Thanx for tha tutorial,
How to give a link from xml to a specific frame number which is designed in Flash
Newbie Poster
Chat is offline Offline
1 posts
since Aug 2009
Aug 31st, 2009
0

Re: Flash-XML Menu

Nice tut. Thank so much
Newbie Poster
baotrungbmt is offline Offline
1 posts
since Aug 2009
Sep 3rd, 2009
0

Re: Flash-XML Menu

thank u so much 4 the good tutorial!!!!!!!!!!
Newbie Poster
shalya is offline Offline
2 posts
since Sep 2009
Feb 10th, 2010
0

Re: Flash-XML Menu

is their any way to make sub menu from this
kindly help..i will be thankful
by the way this tutorial is very helpful.thanks
Last edited by tahseendani; Feb 10th, 2010 at 3:26 am.
Newbie Poster
tahseendani is offline Offline
1 posts
since Feb 2010
Apr 26th, 2010
0

Re: Flash-XML Menu

I'm a newby to flash and other active styles of web development. I have lots of years in experience with just plain HTML but now want to add more updated abilities to the sites I create.

I was looking at this tutorial and I basically use Dreamweaver MX and am wondering what program I need to download/purchase etc. to be able to do this tutorial?

I would also like to be able to have a drop down menu with this menu. Though it doesn't have to be flashy.

Any help would be appreciated.

I found your site through Dynamic Drive. I have used this site for many years for scripts but now seem to be in need of learning a lot more about basic HTML coding.

Thanks in advance for any help.
Light Poster
Kaycy is offline Offline
29 posts
since Apr 2010
Message:
Previous Thread in Site Layout and Usability Forum Timeline: [R.fm] Project - Need help! :)
Next Thread in Site Layout and Usability Forum Timeline: Meta Tags





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC