先贴代码:
1. Application
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="*">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
public function doit(){
com1.label1.text=textInput.text;
}
]]>
</mx:Script>
<mx:TextInput id="textInput" x="290" y="77" change="doit()"/>
<mx:TextInput id="textInput2" x="490" y="77"/>
<mx:ViewStack x="290" y="162" id="viewstack1" width="640" height="478">
<mx:Canvas label="" width="100%" height="100%">
<ns1:firstPage x="10" y="21" width="598" height="432" names="{textInput2.text}" id="com1">
</ns1:firstPage>
</mx:Canvas>
</mx:ViewStack>
</mx:Application>
2. conponent
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
<mx:Script>
<![CDATA[
[Bindable]
public var names:String;
public function showit():void{
label1.text=names;
label2.text=Application.application.textInput2.text;
}
]]>
</mx:Script>
<mx:Button click="showit()" label="change">
</mx:Button>
<mx:Label x="105.5" y="125" width="189" id="label1" text="haha"/>
</mx:Canvas> <mx:Label x="105.5" y="225" width="189" id="label2" text="haha"/>
稍做讲解:
方法一 :
在component中 申明属性 public var names:String;
Application 中直接可以相其传值:
<ns1:firstPage x="10" y="21" width="598" height="432" names="{textInput2.text}" id="com1">
</ns1:firstPage>
方法二 :
在Application 中直接通过ID调用component
com1.label1.text=textInput.text;
在conponent中可以通过Application.application 取得application