7/10/2010 3:32:58 PM
Title:
How do I add URL links to the MenuBar component in Flash CS3?
I am using the MenuBar for my website menu and I want to set the buttons to link to my website pages.
I've followed instructions in both my manual and the Flash help and I'm still a bit lost. I don't know a line of Actionscript except stop(); Code please.
Thanks
Shawn
Points: 680
Posts:0
7/10/2010 9:45:36 PM
there is no nitive functionality in flex menubar to use links. you can extend the menubar class to add such functionality
7/11/2010 1:08:24 AM
see this example to use menuBar in flex to open links . We are using here "navigateToURL" to open link on menuItem click
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init();" >
<mx:Script>
<![CDATA[
import mx.events.MenuEvent;
import mx.controls.Alert;
import mx.collections.*;
[Bindable]
public var menuCollection :XMLListCollection;
private var menubarXML:XMLList =
<>
<menuitem label="Menu1" data="top">
<menuitem label="yahoo.com" data="1"/>
<menuitem label="msn.com" data="2"/>
</menuitem>
<menuitem label="Menu2" data="top">
<menuitem label="MenuItem 3" data="3"/>
</menuitem>
</>;
// create menu items
private function init():void {
menuCollection = new XMLListCollection(menubarXML);
}
// click handler for menubar
private function menuHandler(event:MenuEvent):void {
if(event.item.@label=="yahoo.com"){
var url:URLRequest = new URLRequest('http://yahoo.com');
navigateToURL(url,'_parent');
}else if(event.item.@label=="msn.com"){
var url:URLRequest = new URLRequest('http://msn.com');
navigateToURL(url,'_parent');
}
}
]]>
</mx:Script>
<mx:Panel title="MenuBar Control Example" height="70%" width="70%" paddingTop="6" paddingLeft="6">
<mx:MenuBar labelField="@label" itemClick="menuHandler(event);" dataProvider="{menuCollection }" />
</mx:Panel>
</mx:Application>
7/11/2010 5:05:02 AM
Will this work in Flash? I don't have/use Flex.
7/11/2010 6:56:28 AM
use the below code to open a url on button click in flash cs
myButton.addEventListener(MouseEvent.CLICK, buttonClick)
//button click function
function buttonClick(evt:Event){
var url:URLRequest = new URLRequest('http://msn.com');
navigateToURL(url,'_parent');
}