本文介绍了如何将Java对象发送到java中的两个mxml文件之间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Flex + java .. 因为我有两个 Sub mxml 文件 Sub1.mxml 和 Sub2.mxml

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

Sub1.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...然后是我的第二个 Mxml 文件..

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

Sub2.mxml 代码..

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);

        }

但在那段时间警报不打印....他们还有其他方式可以访问 Sub1.mxml 到 Sub2.mxml 文件中的 editTimetableVO 吗...

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

推荐答案

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);

    }

这篇关于如何将Java对象发送到java中的两个mxml文件之间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 01:23