how to send Java object into between two mxml files in java?

白昼怎懂夜的黑 提交于 2019-12-24 21:15:13

问题


I'm Using Flex + java .. in that i have two Sub mxml files Sub1.mxml and Sub2.mxml

Sub1.mxml code..

[Bindable] private var editTimetableVO:TimetableVO;
        public function forwardToCreateEvent(event:MouseEvent):void
        {
            editTimetableVO = new TimetableVO();
editTimetableVO=editDataGrid.selectedItem as TimetableVO;//editDataGrid is DataGrid id
                Alert.show("value   "+editTimetableVO.startDate);
            }

Hear Alert is Print some date it is good... then my Second Mxml file..

Sub2.mxml code..

public var myEditEvent:Sub1 = new Sub1();
private var timetableVO:TimetableVO = new TimetableVO();

    //  private var editTimetableVO:TimetableVO = new TimetableVO();
        protected function init(event:FlexEvent):void
        {
            Alert.show("Show");
            timetableVO=myEditEvent.editDataGrid.selectedItem as TimetableVO;

            Alert.show("value "+timetableVO.startDate);

        }

But in that time Alert not Printing .... Is their any other way to access to editTimetableVO in Sub1.mxml to Sub2.mxml file...


回答1:


package
{
public class ModelLocator{
    public static var instance:ModelLocator;

    public var editTimetableVO:*;

    public function ModelLocator(instance:SingletonEnforcer){}

    public static function getInstance():ModelLocator{
        if(!instance){
            instance = new ModelLocator(new SingletonEnforcer());
        }
        return instance;
    }
}

}class SingletonEnforcer{}

// sub1.mxml
[Bindable]private var model:ModelLocator = ModelLocator.getInstance();
    public function forwardToCreateEvent(event:MouseEvent):void
    {
        model.editTimetableVO = new TimetableVO();
        model.editTimetableVO=editDataGrid.selectedItem as     TimetableVO;//editDataGrid is DataGrid id
        Alert.show("value   "+model.editTimetableVO.startDate);
        }


// Sub2.mxml
[Bindable]private var model:ModelLocator = ModelLocator.getInstance();
    protected function init(event:FlexEvent):void
    {
        Alert.show("Show");
        model.timetableVO=myEditEvent.editDataGrid.selectedItem as TimetableVO;

        Alert.show("value "+model.timetableVO.startDate);

    }



回答2:


Try to create a modelLocator (singleton class and put reference of "editTimetableVO" in that file). This way only a single instance of "editTimetableVO" variable exist in whole application lifecycle, as you have declared this variable as Bindable so changes happen anywhere in application will reflect instantly.



来源:https://stackoverflow.com/questions/14098540/how-to-send-java-object-into-between-two-mxml-files-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!