2 Replies Latest reply on Sep 17, 2006 10:03 PM by Kotowsky

    Embedded AS3 SWF access in Flex 2

      I have an SWF (Action Script 3) created in Flash 9 Alpha Public.
      I can access all its methods and variables when using SWFloader, but fail to do so when embedding it by using [Embed] tag.

      I need to do it to use it as a custom cursor (CursorManager accepts objects of Class type as cursors). Before I was using SWF 8 (AS2) with LocalConnection, but since the new SWF 9 is in Action Script 3, I want to use it directly.

      The code looks like this:

      [Embed(source = "cursor_9.swf")]
      private var newCursorSymbol:Class;

      private function changeCursor(event:MouseEvent):void

      The question is. Can I, and if I can, then, how, access this swf methods from within a Flex 2 application?
      or else, can the CursorManager somehow accept the content of SWFloader, which is a MovieClip object?

      Thank you
        • 1. Re: Embedded AS3 SWF access in Flex 2
          inlineblue Level 1
          This is tough. The DisplayObject that represents the customer cursor is instantiated internally by the CursorManager and is stored in a private variable, so there's no way to get at it. I believe there is a hack you can do if you ever only have one instance of that cursor. The Class you pass to the CursorManager can be any DisplayObject, so you can cook one up to wrap your SWF. For example, call it MyCursor.mxml:

          <mx:Canvas xmlns:mx="...">
          public static var sCursorLoader: SWFLoader;

          <mx:SWFLoader id="loader" source="cursor_9.swf" creationComplete="sCursorLoader = loader"/>

          And then use the CursorManager:


          The idea is that once the CursorManager instantiates the MyCursor class, the static variable will point to the SWFLoader, so you can access it in a global way:


          Of course, you'll have to put in some kind of delay to make sure the SWF is completely loaded, etc. This is just something I thought of off the top of my head, so take it with a grain of salt. :-)
          • 2. Embedded AS3 SWF access in Flex 2
            Kotowsky Level 1
            Thanks for the tip.
            It compiles but does now show the cursor.
            It does not seem to load the MyCursor class at all. :-(

            The help file though delivers the following.
            public var flexAppCls:Class;

            In this example, you define a class named flexAppCls that represents the embedded SWF file. Flex defines flexAppCls as a reference to a subclass of the mx.core.MovieClipLoaderAsset class, which is a subclass of the flash.disaply.MovieClip class. Therefore, you can manipulate the embedded SWF file by using the methods and properties of the MovieClipLoaderAsset class. ..."

            It says, "you can manipulate", but does not say how. :-)