开发者

how to give hyperlink in flex

i have source code of flex as below:-

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:MenuBar labelField="@label">
<mx:XMLList>
<menuitem label="File">
<menuitem label="New" />
<menuitem label="Open"/>
</menuitem>
<开发者_JAVA百科menuitem label="Edit"/>
<menuitem label="Source"/>
</mx:XMLList>
</mx:MenuBar>
</mx:Application>

i this i want on clicking new url www.google.com should open then how will i do this.


Now that you added the code what you have to do is to add to the MenuBar a click handler.

In adition to my past answer you have to do this.

1st: Add an id to the MenuBar (Recomended) 2nd: Do something like this:

http://livedocs.adobe.com/flex/3/langref/mx/controls/MenuBar.html

I took the code from the Adobe example and you can see it better on the link above.

<mx:MenuBar labelField="@label" itemClick="menuHandler(event);" />

// Event handler for the MenuBar control's itemClick event.
            private function menuHandler(event:MenuEvent):void  {
                // Don't open the Alert for a menu bar item that 
                // opens a popup submenu.
                if (event.item.@data != "top") {
                    Alert.show("Label: " + event.item.@label + "\n" + 
                        "Data: " + event.item.@data, "Clicked menu item");
                }        
            }

Once you added the script block and the event handler to the MenuBar you can handle the events based on the current item, and you can add something like in my first answer:

if(event.item.@label == "What ever you need"))
{
 navigateToURL(new URLRequest("http://www.google.com"), "_blank");
}

Hope it helps!!


If you want to open an URL from a FLEX application on a new window you have to do this using AS3:

navigateToURL(new URLRequest("YOUR URL ADDRESS"), "OPTION");

Where option can be:

_blank: To open in a new window or tab.

_self: To open in the current window or tab.

Example:

navigateToURL(new URLRequest("http://www.google.com"), "_blank");

... would open Google on a new tab.

Hope it's what you are looking for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜