flex 学习笔记之 Application与子component交互的两个方法

先贴代码:

 

 

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

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值