之前做网站时,在顶部导航处,要设置类似普通网页的导航栏,却在flex的导航组件中找不到方便可用的组件,心急之下上网收刮了一番,也不得要领,便自己根据astionscript的url语法,摸索着设计了如下超链接,希望对有需要的朋友提供一点参考!
一、设置click响应方法,并插入转向文件路径,同目录下直接写文件名即可:
<mx:Script>
<![CDATA[
protected function index_link_clickHandler(event:MouseEvent):void {
var u:URLRequest=new URLRequest("index.htm");
navigateToURL(u,"_self");
}
protected function mfc_link_clickHandler(event:MouseEvent):void {
var u:URLRequest=new URLRequest("mfc.htm");
navigateToURL(u,"_self");
}
protected function mfs_link_clickHandler(event:MouseEvent):void {
var u:URLRequest=new URLRequest("mfs.htm");
navigateToURL(u,"_self");
}
protected function mff_link_clickHandler(event:MouseEvent):void {
var u:URLRequest=new URLRequest("mff.htm");
navigateToURL(u,"_self");
}
protected function myblog_link_clickHandler(event:MouseEvent):void {
var u:URLRequest=new URLRequest("myblog.htm");
navigateToURL(u,"_self");
}
]]>
</mx:Script>
二、设置Button,定义id传递ActionScript事件
<mx:Button x="35" y="66" label="主页" id="index_link" click="index_link_clickHandler(event)"/>
<mx:Button x="95" y="66" label="My favorite country" id="mfc_link" click="mfc_link_clickHandler(event)" enabled="true"/>
<mx:Button x="258" y="66" label="My favorite singer" id="mfs_link" click="mfs_link_clickHandler(event)"/>
<mx:Button x="412" y="66" label="My favorite flower" id="mff_link" click="mff_link_clickHandler(event)"/>
<mx:Button x="568" y="66" label="May的个人档" id="myblog_link" click="myblog_link_clickHandler(event)"/>