5 Replies Latest reply on Dec 10, 2009 9:22 PM by Flex harUI

    Accessing Image (content) functions

    Jason Villmer Level 1

      I'm building an application using the Flash Builder 4 Beta 2. In this application I have an Image (class) instance. I also have an event listener that calls a function when the Image has loaded it's content. One of the things it does is check whether loaded Image content (swf) has a public function called _receiver. If so, it calls the function with a string (parameter). For example _receiver("hello world").

       

      Now, this works perfectly fine if the Image loads a swf created in the Flash IDE. The Flash Builder Image class loads the swf, recognizes that the loaded swf file contains a function called "_receiver" and calls it with a string parameter.

       

      However, when I attempt to load swf files created in Flash Builder 4 Beta 2 I get errors despite having the public _receiver function. (in the fx:Script AS3 area) First it was mentioning a compatibility error, so I turned on the Use Flex 3 Compatibility Mode checkbox. Then it was giving me errors. Any ideas why?

       

      Jason

        • 1. Re: Accessing Image (content) functions
          David_F57 Level 5

          Hi,

           

          Have you tried to declare the function as public static ?

           

           

          David

          • 2. Re: Accessing Image (content) functions
            Jason Villmer Level 1

            David, here's the AS3 in the Flash IDE project. I have a text field called "box". This works fine:

             

             

            function _receiver(time:uint):void { box.text=time.toString() }

             

             

             

            Here is the same function in Flash Builder 4 Beta 2. This does not work:


             

            <?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:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768" width="300" height="50">

            <fx:Declarations>

            </fx:Declarations>

             

             

            <fx:Script>

            <![CDATA[

                 public function _receiver(time:uint):void{box.text=time.toString()}

            ]]>

            </fx:Script>

             

            <s:TextInput width="280" textAlign="center" contentBackgroundColor="#FF0000" horizontalCenter="0" verticalCenter="0" borderVisible="false" text="hello" id="box"/>

             

            </s:Application>

            • 3. Re: Accessing Image (content) functions
              Jason Villmer Level 1

              By the way, trying to access the public function of the swf built in Flash Builder 2 (see previous code) I get this error (in the parent app):

               

              Error: Skin for lucid.Image1528.FlexLoader1529.instance2210.receiver1531.SkinnableContainerSkin1532.conte ntGroup.box cannot be found.

              at spark.components.supportClasses::SkinnableComponent/attachSkin()

              at spark.components.supportClasses::SkinnableComponent/validateSkinChange()

              at spark.components.supportClasses::SkinnableComponent/createChildren()

              at mx.core::UIComponent/initialize()[E:\dev\gumbo_beta2\frameworks\projects\framework\src\mx \core\UIComponent.as:6874]

              at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\gumbo_beta2\frameworks\pro jects\framework\src\mx\core\UIComponent.as:6766]

              at mx.core::UIComponent/addChildAt()[E:\dev\gumbo_beta2\frameworks\projects\framework\src\mx \core\UIComponent.as:6473]

              at spark.components::Group/addDisplayObjectToDisplayList()

              at spark.components::Group/http://www.adobe.com/2006/flex/mx/internal::elementAdded()

              at spark.components::Group/setMXMLContent()

              at spark.components::Group/set mxmlContent()

              at spark.components::SkinnableContainer/set mxmlContent()

              at spark.components::SkinnableContainer/createDeferredContent()

              at spark.components::SkinnableContainer/createContentIfNeeded()

              at spark.components::SkinnableContainer/createChildren()

              at mx.core::UIComponent/initialize()[E:\dev\gumbo_beta2\frameworks\projects\framework\src\mx \core\UIComponent.as:6874]

              at spark.components::Application/initialize()

              at receiver/initialize()

              at mx.managers.systemClasses::ChildManager/childAdded()[E:\dev\gumbo_beta2\frameworks\projec ts\framework\src\mx\managers\systemClasses\ChildManager.as:176]

              at mx.managers::SystemManager/initializeTopLevelWindow()[E:\dev\gumbo_beta2\frameworks\proje cts\framework\src\mx\managers\SystemManager.as:2808]

              at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::kickOff()[E:\dev\gumbo_beta2\frameworks\projec ts\framework\src\mx\managers\SystemManager.as:2623]

              at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::preloader_completeHandler()[E:\dev\gumbo_beta2 \frameworks\projects\framework\src\mx\managers\SystemManager.as:2532]

              at flash.events::EventDispatcher/dispatchEventFunction()

              at flash.events::EventDispatcher/dispatchEvent()

              at mx.preloaders::Preloader/timerHandler()[E:\dev\gumbo_beta2\frameworks\projects\framework\ src\mx\preloaders\Preloader.as:530]

              at flash.utils::Timer/_timerDispatch()

              at flash.utils::Timer/tick()

              • 4. Re: Accessing Image (content) functions
                David_F57 Level 5

                Hi,

                 

                I think I misunderstood what you where trying to do, There is a difference between a swf created by flash and one created by flashbuilder. At a guess what you are doing is failing becuase the the mx manager knows nothing about spark plus you have a different methodology beteween a flex application looping 2 frames and the flash swf which is play and stop.

                 

                I think what you are trying to do should be done either as a component or a modue (that way you don't have to think about the flex runtime libraries).

                 

                 

                David.

                • 5. Re: Accessing Image (content) functions
                  Flex harUI Adobe Employee

                  The Application is not the top-level displayobject (root) in a Flex SWF.  It is parented by a SystemManager.  And as David says, it is created on the second frame.  And to make it even harder, the children of the Application can be created even later, on subsequent frame ticks.  The protocol for talking to a loaded Flex app is to:

                   

                  1) wait for SWFLoader's Event.COMPLETE event

                  2) attach a listener to swfLoader.content for "applicationComplete"

                  3) when that event fires, the app is pretty much ready to go and can be accessed via

                       swfLoader.content.application

                  and then you can try to call swfLoader.content.application._receiver()

                   

                  Alex Harui

                  Flex SDK Developer

                  Adobe Systems Inc.

                  Blog: http://blogs.adobe.com/aharui