Flex中窗体参数传递方法


1. 调用窗体
A 窗体是一个applicaton窗体 B 窗体是自定义窗体(类似Dialog之类的窗体,本身并不能独立运行)
A 窗体 片断代码如下:

<textarea cols="50" rows="15" name="code" class="xhtml">&lt;mx:Script&gt; &lt;!--[CDATA[ import mx.containers.TitleWindow; import mx.managers.PopUpManager; function ShowDetailDialog(){ var oInitObj:Object = new Object(); oInitObj.title = "FX-Blog Details"; oInitObj.width = 400; oInitObj.height = 480; oInitObj.x = 350; oInitObj.mainApp = this; oInitObj.strDetailTitle = "aaa"; oInitObj.strDetailDetails = "bbb"; var DetailsDialogInstance:Object = TitleWindow(PopUpManager.createPopUp(_root, B, true, oInitObj, false)) } ]]--&gt; &lt;/mx:Script&gt; &lt;mx:Button label="Click" click="ShowDetailDialog()" width="61"/&gt;</textarea>

B 窗体 片断代码如下:
<textarea cols="50" rows="15" name="code" class="xhtml">&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;mx:TitleWindow xmlns:mx="http://www.macromedia.com/2003/mxml" closeButton="true" click="this.deletePopUp();" alpha="50" initialize="initComponent()"&gt; &lt;mx:Script&gt; &lt;!--[CDATA[ public var mainApp:index = null; public var strDetailTitle:String; public var strDetailDetails:String; } ]]--&gt; &lt;/mx:Script&gt; &lt;mx:TextArea" text="{strDetailTitle}" editable="false" width="100%" alpha="0" height="240" vScrollPolicy="auto"/&gt; &lt;mx:TextArea" text="{strDetailDetails}" editable="false" width="100%" alpha="0" height="240" vScrollPolicy="auto"/&gt; &lt;/mx:TitleWindow&gt;</textarea>

以上,当在A窗体点击button的时候,触发Click event然后调用ShowDetailDialog这个function,在这个function中红色的字体是必须要注意的,其中strDetailTitle和strDetailDetails这个两个变量就是要传递参数的变量和B窗体中的strDetailTitle和strDetailDetails必须一致,否则在Flex中不认哦。这样当点击button后,就会调用B窗体并且把strDetailTitle和strDetailDetails传递到B窗体的textArea中了
其中
var DetailsDialogInstance:Object = TitleWindow(PopUpManager.createPopUp(_root, B, true, oInitObj, false)
这行代码中的B一定要和A在同一个文件夹中,并且名字和和B的外部名称一致,否则也会失败的!

你可能感兴趣的:(String,object,function,Flex,button,encoding)