简体   繁体   中英

Flex4 Modules / Passing Data

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]

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM