【发布时间】:2011-01-01 04:09:38
【问题描述】:
我有一个带弹出式孩子的父母。当父加载时,我必须在弹出窗口中调用一个函数而不显示弹出窗口(因此,我加载“pupLove”但不将其包含在布局中)......然后我将此数据传递给父级。当用户手动单击另一个按钮打开弹出窗口时,会调用相同的函数并将数据传递给父级。但是,我无法将 dg.length 传递给父级。我相信根本问题是我正在加载“pupLove”,因此父母感到困惑......我猜如果我摆脱“pupLove”我可以正确传递数据但需要调用孩子的父级的creationComplete函数....我该怎么做?
这是我的父母:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
backgroundColor="green" width="50%" height="100%"
xmlns:local="*"
>
<fx:Script>
<![CDATA[
import pup;
import mx.managers.PopUpManager;
public function showPup(evt:MouseEvent):void {
var ttlWndw:pup = PopUpManager.createPopUp(this, pup, true) as pup;
PopUpManager.centerPopUp(ttlWndw);
}
]]>
</fx:Script>
<mx:VBox>
<local:pup id="pupLove" visible="false" includeInLayout="false" />
<s:Button click="showPup(event);" label="launch Pup" />
<mx:Text id="Ptest" color="black" text="from Parent:{pupLove.dg.length}" />
</mx:VBox>
</s:Application>
还有一个名为“pup.mxml”的弹出子窗口:
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">
<fx:Script>
<![CDATA[
public function init():void{
// send php call
}
import mx.events.CloseEvent;
import mx.managers.PopUpManager;
private function removePup(evt:Event):void {
PopUpManager.removePopUp(this);
}
]]>
</fx:Script>
<fx:Declarations>
<s:ArrayCollection id="dg">
</s:ArrayCollection>
</fx:Declarations>
<s:TitleWindow width="100%" height="100%" close="removePup(event)">
<mx:VBox>
<mx:Text id="test" color="red" text="from Child:{dg.length}" />
<s:Button label="add Items" click="dg.addItem({id:'cat'})" />
</mx:VBox>
</s:TitleWindow>
</s:Group>
更新:我想我的问题可以更简单地表述为:“有没有一种方法可以从父级调用子级函数而不实际加载子级?”
【问题讨论】:
标签: actionscript-3 apache-flex popup