RIACHINA 中国RIA开发者论坛RIA 客户端开发FLEX 专区 关于TitleWindow调用Mian文件的function的问题!

关于TitleWindow调用Mian文件的function的问题!

关于TitleWindow调用Mian文件的function的问题!

示例如下:
Main:
public function mainFunc():void{
//....
}
TitleWindow:
[Bindable] public var mainApp:Main;
mainApp.mainFunc();
为什么提示方法有错误呢?
 

回复:关于TitleWindow调用Mian文件的function的问题!

[Bindable] public var mainApp:Main;

你这里声明了一个新的mainApp,  即没new,也没指向,那它指的是什么?
Impossible is nothing ...
http://kevin-lu.blogspot.com/
 

回复: 关于TitleWindow调用Mian文件的function的问题!

Sorry,没说明白,但最后还是网上找了个类似的,在里面稍微改动下,解决了这个问题,看看最终的结果是什么,说出来有点神奇:居然是TitleWindow弹出自身;
TitleWindow:
<?xml version="1.0" encoding="utf-8"?>
<!-- TitleWindowData.mxml
  A sample custom pop-up that extends TitleWindow-->
<mxitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
  creationComplete="initComponent()"
  showCloseButton="true"
  close="closeWindow()">
<mx:Script><![CDATA[
    import mx.validators.ValidationResult;
  import mx.managers.PopUpManager;
  import mx.collections.ArrayCollection;
 
[Bindable]public var mainAppitleWindowTest = null; 
[Bindable]public var gsMyString:String;     
[Bindable]public var gnMyNumber:Number;     
[Bindable]public var acItemsSelected:ArrayCollection;

private function initComponent():void
{
 
}
private function getMainAppFunction():void{
    mainApp.showTitleWindow();
}
private function closeWindow():void
{
  PopUpManager.removePopUp(this);
}//closeWindow

private function showFinalSelection(oEvent:Event):void
{
  mainApp.tiFinalSelection.text = oEvent.target.selectedItem.album;
}//showFinalSelection

]]></mx:Script>
<mxext text="The data grid below shows the selectedItems in the data grid in the Main app. This dataProvider is bound to a local variable which is set by Main App datagrid itemClick. Select additional items(ctrl-click) in Main App, they will display here. Select an item here. It will display in Main App 'Final Selection' control." width="300" />
    <mx:Button label="getMainAppFunction" click="getMainAppFunction();"/>
<mxataGrid id="dg2" rowCount="3"
  dataProvider="{mainApp.acItemsSelected}"
  change="showFinalSelection(event)" >
  <mx:columns>
  <mx:Array>
    <mxataGridColumn headerText="Artist" dataField="artist" />
    <mxataGridColumn headerText="Price" dataField="price" editable="true"/>
    <mxataGridColumn headerText="Album" dataField="album" />
  </mx:Array>
  </mx:columns>   
</mxataGrid>

<mx:HBox >
  <mxabel id="lblMyNumber" text="{gnMyNumber}"  width="100"/>
  <mxext text="Bound to local variable set at pop-up. Changes to Main App control do NOT change this" width="200" />
</mx:HBox>
<mx:HBox >
  <mxabel text="{mainApp.gsBindMe}"  width="100"/>
  <mxext text="Bound to mainApp local variable via passed in reference. Changes in Main App DO change this." width="200"  />
</mx:HBox> 
 
</mx:TitleWindow>

Main:
<?xml version="1.0" encoding="utf-8"?>
<!-- TitleWindowDataTest.mxml
  An application that uses custom pop-up TitleWindowData-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" horizontalAlign="left" layout="vertical"
  initialize="initApp()">
<mx:Script><![CDATA[
import mx.containers.TitleWindow;
import mx.managers.PopUpManager;
import mx.collections.ArrayCollection;
[Bindable]public var gsBindMe:String = "Change me!" ;    //
[Bindable]private var acDP2:ArrayCollection;
[Bindable]public var acItemsSelected:ArrayCollection;      //set by itemClick

private function initApp():void
{
  acDP2 = new ArrayCollection();
  acDP2.addItem({artist:"Pink Floyd",price:29.99,album:"Meddle"});
  acDP2.addItem({artist:"Pink Floyd",price:29.99,album:"More"});
  acDP2.addItem({artist:"Genesis",price:22.99,album:"Trespass"});
  acDP2.addItem({artist:"Yes",price:22.99,album:"Close to the Edge"});
  acDP2.addItem({artist:"King Crimson",price:21.99,album:"Wake of Posiedon"});
}//

public function showTitleWindow():void
{
  var titleWindowInstance:TitleWindowData =
        TitleWindowData(PopUpManager.createPopUp(this,
                TitleWindowData,
                false));    //instantiate and show the title window

  PopUpManager.centerPopUp(titleWindowInstance);
  titleWindowInstance.title = "Non-Modal Title Window Data";//built-in property
  titleWindowInstance.width = 400;                //built-in property
  titleWindowInstance.height = 450;                //built-in property 
  titleWindowInstance.mainApp = this;                      //Reference to the main app scope
  titleWindowInstance.gnMyNumber = parseFloat(tiMyNumber.text);  //Pass a simple value to the popup
}

private function showSelectedItems(event:Event):void
{
  acItemsSelected = new ArrayCollection(dg2.selectedItems)
}//
]]></mx:Script>
  <mxabel text="Main App" fontSize="18" />
<mx:Text text="Selected Items will be passed into the pop-up. Select an item and click 'Show Title Window' button"  width="300"/>
<mx:DataGrid id="dg2" allowMultipleSelection="true" itemClick="showSelectedItems(event)"
  dataProvider="{acDP2}" >
  <mx:columns>
  <mx:Array>
    <mx:DataGridColumn headerText="Artist" dataField="artist" />
    <mx:DataGridColumn headerText="Price" dataField="price" editable="true"/>
    <mx:DataGridColumn headerText="Album" dataField="album" />
  </mx:Array>
  </mx:columns>   
</mx:DataGrid>

<mx:HBox >
  <mxabel text="MyNumber:"  width="100"/>
  <mx:TextInput id="tiMyNumber"  text="99"/>
</mx:HBox>
<mx:HBox >
  <mxabel text="Bind Me"  width="100"/>
  <mx:TextInput id="tiBindMe" text="{gsBindMe}"
  change="gsBindMe = tiBindMe.text"/>
</mx:HBox>
<mx:Button label="Show Title Window (Non-Modal)" click="showTitleWindow()"/>
<mx:HBox >
  <mx:Text text="Final Selection: From item selected in pop-up"  width="100"/>
  <mx:TextInput id="tiFinalSelection"/>
</mx:HBox> 
</mx:Application>

希望加点积分哦:D
 

回复:关于TitleWindow调用Mian文件的function的问题!

哇。。代码一大堆。。。怎么看呀。。。不看了,呵呵。。
Impossible is nothing ...
http://kevin-lu.blogspot.com/
 

回复: 关于TitleWindow调用Mian文件的function的问题!

不是吧,那我干脆把那个最终效果的swf帖上来吧。
 附件: 您所在的用户组无法下载或查看附件
 

回复:关于TitleWindow调用Mian文件的function的问题!

的确是个好玩的东西
 

回复:关于TitleWindow调用Mian文件的function的问题!

顶一下,再次回味下自己弹出自己的感觉!
 

回复: 关于TitleWindow调用Mian文件的function的问题!

今天扩展下,想调用main文件下的某个控件的方法和属性,同样的操作,就出现点麻烦了,因为当初的[Bindable]public var mainAppitleWindowTest = null;  为null,例如用main下的flv.source赋值 为titlewindow下的一个string,就会发生引用空对象的方法和属性的报错了,又怎么解决呢?
 

回复:关于TitleWindow调用Mian文件的function的问题!

var  manapp:Main = Main(Application.application);

mainapp.fun();

fun()为你的flex Main文件中的function
 

回复: 关于TitleWindow调用Mian文件的function的问题!

就是这个意思,昨天用set的方法也通过了,不过没楼上的便捷,学习了!!
 

回复:关于TitleWindow调用Mian文件的function的问题!

怎么看着这么眼熟呀^_^
 
1  /  1  页   1 跳转

版权所有 riachina.com   Sitemap

Powered by Discuz!NT 2.1.202    Copyright © 2001-2008 Comsenz Inc.
Processed in 0 second(s) (Cached).
返顶部