Flex将字符串传递给另一个mxml,始终获得公共变量的初始值

时间:2014-12-10 03:00:09

标签: flex mxml public

我在search.mxml中有一个公共变量sqlQuery,我想在searchResult.mxml中使用它,但它无法正常工作。

情景1
  在我的search.mxml

[Bindable] public static var sqlQuery:String;
In lower part of search.mxml, I set the value of sqlQuery

在我的searchResult.mxml

Alert.show("query from other mxml = " + search.sqlQuery);  

每次我得到空值

Scenaro 2

如果我为public vaiable的定义赋值:

在我的search.mxml

[Bindable] public static var sqlQuery:String = "ABC";
In lower part of search.mxml, I set the value of sqlQuery

在我的searchResult.mxml

Alert.show("query from other mxml = " + search.sqlQuery);  

每次我获得价值" ABC"

似乎我只能在另一个mxml中获取变量的初始值,我的代码出了什么问题?

编辑:search.mxml的详细信息:

[Bindable] public static var sqlQuery:String;

        public function handleEvent():void
        {           

            sqlQuery = "SELECT ItemNo,ItemType,ItemName,Location FROM ITEM_DETAILS WHERE";

                if (ItemNo.text){  // BQ_NO has value
                    sqlQuery = sqlQuery + " ItemNo= '" + ItemNo.text + "'"
                }

                if (ItemType.text){
                        sqlQuery = sqlQuery + " and ItemType= '" + ItemType.text + "'"
                    }
                }

                if (ItemName.text){
                        sqlQuery = sqlQuery + " and ItemName = '" + ItemName.text + "'"
                }

                if (Location.text){
                        sqlQuery = sqlQuery + " and Location LIKE '%" + Location.text + "%'"
                }

                Alert.show("final sql Query = " + sqlQuery);   
                // this is what I need to pass to searchResult.mxml

            }
                var widgetId:Number = ViewerContainer.getInstance().widgetManager.getWidgetId("Search Result");  
                AppEvent.dispatch(AppEvent.WIDGET_RUN, widgetId); 

                this.setState("closed");    
        }

这是我的searchResult.mxml,它在search.mxml中获取sqlQuery值:

import .search

public function init():void {

     Alert.show("query from search mxml = " + search.sqlQuery);
}

0 个答案:

没有答案