Flex4 模块/传递数据

发布于 2024-11-02 00:38:57 字数 8100 浏览 4 评论 0原文

我有一个加载模块的 Flex 4 应用程序。一切工作正常,除了我无法创建和对象或将对象强制转换为我的模块的类型。在运行时它会抛出错误。

我不确定模块、Flex4和spark是否有问题?我尝试了许多不同的方法来设置/投射这些对象,但似乎没有任何效果。

我需要获取这些对象,以便将数据传递到模块。感谢您的任何帮助。

Main.mxml...

<?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:esri="http://www.esri.com/2008/ags" 
               xmlns:mx="library://ns.adobe.com/flex/mx" 
               minWidth="955" minHeight="600" applicationComplete="init();"
                >
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <fx:Script>

        <![CDATA[
            import com.gisworkshop.widgets.DataFrame.DataFrame;
            import com.gisworkshop.widgets.DataFrame.IDataFrame;

            import mx.containers.Canvas;
            import mx.core.IVisualElement;
            import mx.events.ModuleEvent;
            import mx.modules.IModuleInfo;
            import mx.modules.ModuleLoader;
            import mx.modules.ModuleManager;

            public var module:IModuleInfo;


            public function init():void{            

                /*  Use the Module Manager to add the module to the app.
                    We have to use the addElement method of the main application so that the componants in the Module are seen.
                    This is a little different from the documentation because we are using spark and Flex 4 in the application. */

                module = ModuleManager.getModule("com/gisworkshop/widgets/DataFrame/DataFrame.swf");                

                module.addEventListener(ModuleEvent.READY, modReadyHandler, false, 0, true);
                module.addEventListener(ModuleEvent.ERROR, modErrorHandler, false, 0, true);
                module.addEventListener(ModuleEvent.UNLOAD, modUnloadHandler, false, 0, true);

                module.load(null, null, null, moduleFactory);

            }

            private function modErrorHandler( moduleEvent:ModuleEvent ):void
            {


            }

            private function modReadyHandler( moduleEvent:ModuleEvent ):void
            {
                this.addElement(module.factory.create() as DataFrame);

                var obj:DataFrame;


            }

            private function modUnloadHandler( moduleEvent:ModuleEvent ):void
            {

                //When we unload the module, remove it from the application
                for (var i:int = 0; i < numElements; i++) {

                    var objModule:Object = this.getElementAt(i);

                    //the object we want to remove has the property "cvsDataFrame"
                    if (objModule.hasOwnProperty("cvsDataFrame")){
                        this.removeElementAt(i);
                    }   

                }

                /*When we unload the module, we remove all the event listeners and anything referenced to the module object.
                  Re-define the event listeners for the module object */

                module = ModuleManager.getModule("com/gisworkshop/widgets/DataFrame/DataFrame.swf");                

                module.addEventListener(ModuleEvent.READY, modReadyHandler, false, 0, true);
                module.addEventListener(ModuleEvent.ERROR, modErrorHandler, false, 0, true);
                module.addEventListener(ModuleEvent.UNLOAD, modUnloadHandler, false, 0, true);

                module.load(null, null, null, moduleFactory);

            }

            private function loadModule():void{

                module.unload();

            }

        ]]>

    </fx:Script>

    <esri:Map id="mainMap">

        <esri:ArcGISDynamicMapServiceLayer id="baseMap" url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"/>
    </esri:Map>

    <mx:Button label="Load" click="loadModule();"/>

</s:Application>

DataFrame...

<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" width="400" height="300" implements="com.gisworkshop.widgets.DataFrame.IDataFrame"

           >
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>

        <![CDATA[

            import com.esri.ags.Map;

            [Bindable]
            private var _Map:Map;

            public function setMap(map:Map):void{

                _Map = map;

            }

            public function zoom():void{

                _Map.zoomIn();

            }

        ]]>

    </fx:Script>

    <mx:Canvas id="cvsDataFrame" width="100" height="50" top="90" left="0" >
        <mx:Button label="Zoom" left="0" top="0" click="zoom();"/>
    </mx:Canvas>

</mx:Module>

IDataFrame 接口...

package com.gisworkshop.widgets.DataFrame
{
    import com.esri.ags.Map;

    import mx.core.IVisualElement;

    public interface IDataFrame 
    {
        function setMap(_Map:Map):void;
        //function 
    }
}

错误:

ArgumentError: Error #2004: One of the parameters is invalid.
    at flash.display::Graphics/drawRoundRect()
    at spark.primitives::Rect/draw()[E:\dev\4.x\frameworks\projects\spark\src\spark\primitives\Rect.as:459]
    at spark.primitives.supportClasses::StrokedElement/updateDisplayList()[E:\dev\4.x\frameworks\projects\spark\src\spark\primitives\supportClasses\StrokedElement.as:143]
    at spark.primitives.supportClasses::GraphicElement/http://www.adobe.com/2006/flex/mx/internal::doUpdateDisplayList()[E:\dev\4.x\frameworks\projects\spark\src\spark\primitives\supportClasses\GraphicElement.as:3893]
    at spark.primitives.supportClasses::GraphicElement/validateDisplayList()[E:\dev\4.x\frameworks\projects\spark\src\spark\primitives\supportClasses\GraphicElement.as:3877]
    at spark.components::Group/updateDisplayList()[E:\dev\4.x\frameworks\projects\spark\src\spark\components\Group.as:956]
    at spark.skins::SparkSkin/updateDisplayList()[E:\dev\4.x\frameworks\projects\spark\src\spark\skins\SparkSkin.as:191]
    at mx.skins.spark::SparkSkinForHalo/updateDisplayList()[E:\dev\4.x\frameworks\projects\sparkskins\src\mx\skins\spark\SparkSkinForHalo.as:118]
    at mx.skins.spark::ButtonSkin/updateDisplayList()[E:\dev\4.x\frameworks\projects\sparkskins\src\mx\skins\spark\ButtonSkin.mxml:66]
    at mx.core::UIComponent/validateDisplayList()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:8709]
    at mx.managers::LayoutManager/validateClient()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:932]
    at mx.core::UIComponent/validateNow()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7792]
    at mx.controls::Button/http://www.adobe.com/2006/flex/mx/internal::viewSkinForPhase()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\Button.as:1985]
    at mx.controls::Button/http://www.adobe.com/2006/flex/mx/internal::viewSkin()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\Button.as:1885]
    at mx.controls::Button/commitProperties()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\Button.as:1631]
    at mx.core::UIComponent/validateProperties()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7933]
    at mx.managers::LayoutManager/validateProperties()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:572]
    at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:700]
    at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1072]

I have a Flex 4 application that loads a module. Everything works fine except that I cant create and object or cast an object to a type of my module. At run time it throws an error.

I'm not sure if there is an issue with modules, Flex4, and spark? I've tried many different ways to set/cast these objects, but nothing seems to work.

I need to get these objects so I can pass data to the module. Thanks for any help.

Main.mxml...

<?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:esri="http://www.esri.com/2008/ags" 
               xmlns:mx="library://ns.adobe.com/flex/mx" 
               minWidth="955" minHeight="600" applicationComplete="init();"
                >
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <fx:Script>

        <![CDATA[
            import com.gisworkshop.widgets.DataFrame.DataFrame;
            import com.gisworkshop.widgets.DataFrame.IDataFrame;

            import mx.containers.Canvas;
            import mx.core.IVisualElement;
            import mx.events.ModuleEvent;
            import mx.modules.IModuleInfo;
            import mx.modules.ModuleLoader;
            import mx.modules.ModuleManager;

            public var module:IModuleInfo;


            public function init():void{            

                /*  Use the Module Manager to add the module to the app.
                    We have to use the addElement method of the main application so that the componants in the Module are seen.
                    This is a little different from the documentation because we are using spark and Flex 4 in the application. */

                module = ModuleManager.getModule("com/gisworkshop/widgets/DataFrame/DataFrame.swf");                

                module.addEventListener(ModuleEvent.READY, modReadyHandler, false, 0, true);
                module.addEventListener(ModuleEvent.ERROR, modErrorHandler, false, 0, true);
                module.addEventListener(ModuleEvent.UNLOAD, modUnloadHandler, false, 0, true);

                module.load(null, null, null, moduleFactory);

            }

            private function modErrorHandler( moduleEvent:ModuleEvent ):void
            {


            }

            private function modReadyHandler( moduleEvent:ModuleEvent ):void
            {
                this.addElement(module.factory.create() as DataFrame);

                var obj:DataFrame;


            }

            private function modUnloadHandler( moduleEvent:ModuleEvent ):void
            {

                //When we unload the module, remove it from the application
                for (var i:int = 0; i < numElements; i++) {

                    var objModule:Object = this.getElementAt(i);

                    //the object we want to remove has the property "cvsDataFrame"
                    if (objModule.hasOwnProperty("cvsDataFrame")){
                        this.removeElementAt(i);
                    }   

                }

                /*When we unload the module, we remove all the event listeners and anything referenced to the module object.
                  Re-define the event listeners for the module object */

                module = ModuleManager.getModule("com/gisworkshop/widgets/DataFrame/DataFrame.swf");                

                module.addEventListener(ModuleEvent.READY, modReadyHandler, false, 0, true);
                module.addEventListener(ModuleEvent.ERROR, modErrorHandler, false, 0, true);
                module.addEventListener(ModuleEvent.UNLOAD, modUnloadHandler, false, 0, true);

                module.load(null, null, null, moduleFactory);

            }

            private function loadModule():void{

                module.unload();

            }

        ]]>

    </fx:Script>

    <esri:Map id="mainMap">

        <esri:ArcGISDynamicMapServiceLayer id="baseMap" url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"/>
    </esri:Map>

    <mx:Button label="Load" click="loadModule();"/>

</s:Application>

DataFrame...

<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" width="400" height="300" implements="com.gisworkshop.widgets.DataFrame.IDataFrame"

           >
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>

        <![CDATA[

            import com.esri.ags.Map;

            [Bindable]
            private var _Map:Map;

            public function setMap(map:Map):void{

                _Map = map;

            }

            public function zoom():void{

                _Map.zoomIn();

            }

        ]]>

    </fx:Script>

    <mx:Canvas id="cvsDataFrame" width="100" height="50" top="90" left="0" >
        <mx:Button label="Zoom" left="0" top="0" click="zoom();"/>
    </mx:Canvas>

</mx:Module>

IDataFrame interface...

package com.gisworkshop.widgets.DataFrame
{
    import com.esri.ags.Map;

    import mx.core.IVisualElement;

    public interface IDataFrame 
    {
        function setMap(_Map:Map):void;
        //function 
    }
}

Error:

ArgumentError: Error #2004: One of the parameters is invalid.
    at flash.display::Graphics/drawRoundRect()
    at spark.primitives::Rect/draw()[E:\dev\4.x\frameworks\projects\spark\src\spark\primitives\Rect.as:459]
    at spark.primitives.supportClasses::StrokedElement/updateDisplayList()[E:\dev\4.x\frameworks\projects\spark\src\spark\primitives\supportClasses\StrokedElement.as:143]
    at spark.primitives.supportClasses::GraphicElement/http://www.adobe.com/2006/flex/mx/internal::doUpdateDisplayList()[E:\dev\4.x\frameworks\projects\spark\src\spark\primitives\supportClasses\GraphicElement.as:3893]
    at spark.primitives.supportClasses::GraphicElement/validateDisplayList()[E:\dev\4.x\frameworks\projects\spark\src\spark\primitives\supportClasses\GraphicElement.as:3877]
    at spark.components::Group/updateDisplayList()[E:\dev\4.x\frameworks\projects\spark\src\spark\components\Group.as:956]
    at spark.skins::SparkSkin/updateDisplayList()[E:\dev\4.x\frameworks\projects\spark\src\spark\skins\SparkSkin.as:191]
    at mx.skins.spark::SparkSkinForHalo/updateDisplayList()[E:\dev\4.x\frameworks\projects\sparkskins\src\mx\skins\spark\SparkSkinForHalo.as:118]
    at mx.skins.spark::ButtonSkin/updateDisplayList()[E:\dev\4.x\frameworks\projects\sparkskins\src\mx\skins\spark\ButtonSkin.mxml:66]
    at mx.core::UIComponent/validateDisplayList()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:8709]
    at mx.managers::LayoutManager/validateClient()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:932]
    at mx.core::UIComponent/validateNow()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7792]
    at mx.controls::Button/http://www.adobe.com/2006/flex/mx/internal::viewSkinForPhase()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\Button.as:1985]
    at mx.controls::Button/http://www.adobe.com/2006/flex/mx/internal::viewSkin()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\Button.as:1885]
    at mx.controls::Button/commitProperties()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\Button.as:1631]
    at mx.core::UIComponent/validateProperties()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7933]
    at mx.managers::LayoutManager/validateProperties()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:572]
    at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:700]
    at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1072]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天生の放荡 2024-11-09 00:38:57

你的问题不在于选角,而在于某种皮肤不兼容。尝试用 Spark 按钮替换 MX 按钮。

您使用什么版本的SDK?

Your problem isn't in casting but some kind of skins incompatibility. Try to replace MX Buttons with Spark ones.

And what version of SDK do you using?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文