26 Replies Latest reply on May 18, 2010 9:23 AM by BKUoP

    Accessing Flash MovieClips in Flex

    BKUoP

      So I've been given some MovieClips, exported for ActionScript, in a swf from one of our Designers and I need to embed each symbol as a separate objects in Flex (running Flex 3.4).  It seems that no matter what I do, I keep getting a "Type Coercion failed: cannot convert  .... to flash.display.MovieClip"

       

      Here is the code I'm using right now:

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" backgroundColor="0xD3D3D3"
          xmlns:view="edu.apollogrp.moviepostergenerator.view.*" creationComplete="init()" xmlns:display="flash.display.*">
          <mx:Script>
              <![CDATA[
                  import flash.display.MovieClip;
                 
                  [Embed(source="assets/swfEmbedTest.swf", symbol="clipBlue")]
                  private var Blue:Class;
                  private var blueSquare:MovieClip;
                 
                 
                  private function init():void
                  {
                      blueSquare = new Blue();
                      moviePosterCanvas.addChild(blueSquare);
                  }
                 
                 
              ]]>
          </mx:Script>

       

          <mx:Canvas id="moviePosterCanvas" width="480" height="672" x="0" y="0" backgroundColor="0xFFFFFF"/>
          <view:ControlPanelsView id="controlPanelsView" width="218" y="0" right="0"/>
      </mx:Canvas>

       

       

       

      What I ultimately need to do is be able to change the text property on a few dynamic text fields inside these MovieClips, which from what I've read seems to be possible...but if its not I'll have to start from scratch.  Any suggestions from someone who may have worked with something similar to this?

        • 1. Re: Accessing Flash MovieClips in Flex
          Flex harUI Adobe Employee

          Maybe they are sprites or buttons and not movieclips

          • 2. Re: Accessing Flash MovieClips in Flex
            BKUoP Level 1

            No, unfortunately when I look at the properties in Flash, the type is MovieClip and their Base class is flash.display.MovieClip.

            • 3. Re: Accessing Flash MovieClips in Flex
              Flex harUI Adobe Employee

              Call describeType on the object and see what it thinks it is made of.

              • 4. Re: Accessing Flash MovieClips in Flex
                mike_morales Level 2

                Not sure if it is the same for flex3 as in flash builder 4, but typically, you have to export MC from flash as swc files. In the movie clips, you want to set them up to use setter and getter methods to change its text properties in the MCs. Then, when you import the swc's into flashbuilder, you can access the getter/setters  in the movieclips.  Used this in a few projects and works quite well.

                • 5. Re: Accessing Flash MovieClips in Flex
                  BhaskerChari Level 4

                  Hi BKUoP,

                   

                  I understand your problem you are getting the TypeCoercion error this is because you can only add child objects to containers that implement IUIComponent. Since MovieClip doesn't implement  IUIComponent it will throw an TypeCoercion exception.

                   

                  The work around for this is to wrap the flash movieclip in UIComponent and then add the uiComp to the container.

                   

                   

                  private

                   

                   

                   

                   

                   

                  function init():void

                  {

                  blueSquare =

                   

                  new Blue();

                   

                  var uiComp:UIComponent = new UIComponent();

                  uiComp.addChild(blueSquare);

                  moviePosterCanvas.addChild(uiComp);

                  }

                   

                   

                  Replace the above function in your code and dont forget to import the namespace .....  import mx.core.UIComponent;

                   

                   

                  Try this it will defenitely work for you...:)

                   

                  Thanks,

                  Bhasker Chari

                  1 person found this helpful
                  • 6. Re: Accessing Flash MovieClips in Flex
                    Karl_Sigiscar_1971 Level 3

                    The alternative is to use the Flex component kit for Flash.

                     

                    It creates a Flex component from a Flash movieclip.

                     

                    AFAIK, this is the best way to use Flash assets in a Flex.

                     

                    The only downside is that it produces a swc when you publish (not a swf), so it's statically linked and compiled into your application swf.

                     

                    http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&extid=1273018

                    http://livedocs.adobe.com/flex/3/flash_component_kit_flex3.pdf

                     

                    Then you can easily instantiate your movieclip in Flex, like so:

                     

                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
                                            xmlns:local="*">

                                   <local:MyMovieClip />


                    </mx:Canvas>

                     

                    ...where MyMovieClip is the name of your movievlip in the Flash library.

                     

                    Note that is it not necessary to have as many different fla/swc files as you have movieclips. You can hold as many as you want in one swc. You can however also use several different such swc files in one project.

                    • 7. Re: Accessing Flash MovieClips in Flex
                      mike_morales Level 2

                      Hi Karl, that is interesting - I typically created a new swc file for 'every' movie clip that I wanted to use in flex, then exported each individually. But you explain that you can have several swc's in one fla, then export them all within one fla file? How is this done? Do you change the publish settings for the fla file to swc, then all movie clips within the fla are also exported too?

                       

                      Also, even though I used the flex component creator plugin for flash, I always had to go back and manually change the movie clip's class to extend a UIMovieClip as opposed to MovieClip otherwise, I couldnt get access to my instance variables from flex. Is that the typical workflow?

                       

                      Mike

                      • 8. Re: Accessing Flash MovieClips in Flex
                        Karl_Sigiscar_1971 Level 3

                        Hi Mike,

                         

                        You do not have to change the Publish Settings in Flash Professional in order to have several MovieClips exported as Flex components.  Publish Settings are set by the Flex component kit for Flash and they are the same for one or several MovieClips. Just select each MovieClip you need exported and select the Convert Symbol to Flex Component command in the Command menu for each prior to publishing the whole project as a swc.

                         

                        Concerning extending UIMovieClip, again this is done automatically by the Flex component kit for Flash when you select the Convert Symbol to Flex Component command in the Command menu . Check that you have the latest version. Maybe you use an old version of it. Do you have both Convert Symbol to Flex Component and Convert Symbol to Flex Container options ?

                         

                        Cheers,
                        Karl.

                        • 9. Re: Accessing Flash MovieClips in Flex
                          BKUoP Level 1

                          @Bhasker,

                           

                          Thanks this got me going in the right direction and does work.  The only other thing that I'm having a problem is with making these object public so I can access them from other classes.  Because blueSquare isn't declared on the global level I can't get to it...and if I declare it as a public var on the global level Flex complains about Blue() being an unrecognized type.

                           

                          Any suggestions anyone?

                          • 10. Re: Accessing Flash MovieClips in Flex
                            BhaskerChari Level 4

                            I am glad it worked for you...regarding your problem please try the following:

                             

                            Decalre these lines in your main application file(which is having <mx:Application/> root tag) as public var

                             

                             

                            [

                            Bindable]

                            [

                            Embed(source="assets/flashswf.swf", symbol="clipBlue")]

                             

                            public var Blue:Class

                             

                             

                            Then use the below lines of code to access the var Blue throughout your application in any class or file.

                             

                             

                             

                             

                             

                            var blueSquare:MovieClip;

                            blueSquare =

                            new Application.application.Blue();

                             

                             

                            Thanks,

                            Bhasker Chari

                            • 11. Re: Accessing Flash MovieClips in Flex
                              BKUoP Level 1

                              Bhasker,

                               

                              Tried it out but I seem to be getting the same "Type Coercion" errors I was getting before.  Seems like it choking when trying to trying to convert that Blue() class to a MovieClip.

                              • 12. Re: Accessing Flash MovieClips in Flex
                                Flex harUI Adobe Employee

                                import flash.utils.describeType;

                                    trace(describeType(Blue).toXMLString());

                                 

                                Post the results.

                                • 13. Re: Accessing Flash MovieClips in Flex
                                  BKUoP Level 1

                                  in the results...replace Blue with Comedy (since Blue was just a test, and I've moved on to the content I'm actually using for this project).  Other than that its all the same.  Here's the results:

                                   

                                  <type name="edu.apollogrp.moviepostergenerator.view::MainView_Comedy" base="Class" isDynamic="true" isFinal="true" isStatic="true">
                                    <extendsClass type="Class"/>
                                    <extendsClass type="Object"/>
                                    <accessor name="prototype" access="readonly" type="*" declaredBy="Class"/>
                                    <factory type="edu.apollogrp.moviepostergenerator.view::MainView_Comedy">
                                      <extendsClass type="mx.core::SpriteAsset"/>
                                      <extendsClass type="mx.core::FlexSprite"/>
                                      <extendsClass type="flash.display::Sprite"/>
                                      <extendsClass type="flash.display::DisplayObjectContainer"/>
                                      <extendsClass type="flash.display::InteractiveObject"/>
                                      <extendsClass type="flash.display::DisplayObject"/>
                                      <extendsClass type="flash.events::EventDispatcher"/>
                                      <extendsClass type="Object"/>
                                      <implementsInterface type="flash.display::IBitmapDrawable"/>
                                      <implementsInterface type="flash.events::IEventDispatcher"/>
                                      <implementsInterface type="mx.core::IFlexDisplayObject"/>
                                      <implementsInterface type="mx.core::IFlexAsset"/>
                                      <implementsInterface type="mx.core::IBorder"/>
                                      <variable name="txtDate" type="flash.display::DisplayObject"/>
                                      <variable name="txtTitle" type="flash.display::DisplayObject"/>
                                      <variable name="fade" type="flash.display::DisplayObject"/>
                                      <variable name="txtTagline" type="flash.display::DisplayObject"/>
                                      <accessor name="measuredHeight" access="readonly" type="Number" declaredBy="mx.core::SpriteAsset"/>
                                      <accessor name="measuredWidth" access="readonly" type="Number" declaredBy="mx.core::SpriteAsset"/>
                                      <method name="move" declaredBy="mx.core::SpriteAsset" returnType="void">
                                        <parameter index="1" type="Number" optional="false"/>
                                        <parameter index="2" type="Number" optional="false"/>
                                      </method>
                                      <accessor name="borderMetrics" access="readonly" type="mx.core::EdgeMetrics" declaredBy="mx.core::SpriteAsset"/>
                                      <method name="setActualSize" declaredBy="mx.core::SpriteAsset" returnType="void">
                                        <parameter index="1" type="Number" optional="false"/>
                                        <parameter index="2" type="Number" optional="false"/>
                                      </method>
                                      <method name="toString" declaredBy="mx.core::FlexSprite" returnType="String"/>
                                      <accessor name="soundTransform" access="readwrite" type="flash.media::SoundTransform" declaredBy="flash.display::Sprite"/>
                                      <accessor name="graphics" access="readonly" type="flash.display::Graphics" declaredBy="flash.display::Sprite"/>
                                      <method name="stopDrag" declaredBy="flash.display::Sprite" returnType="void"/>
                                      <accessor name="useHandCursor" access="readwrite" type="Boolean" declaredBy="flash.display::Sprite"/>
                                      <method name="startDrag" declaredBy="flash.display::Sprite" returnType="void">
                                        <parameter index="1" type="Boolean" optional="true"/>
                                        <parameter index="2" type="flash.geom::Rectangle" optional="true"/>
                                      </method>
                                      <accessor name="dropTarget" access="readonly" type="flash.display::DisplayObject" declaredBy="flash.display::Sprite"/>
                                      <accessor name="hitArea" access="readwrite" type="flash.display::Sprite" declaredBy="flash.display::Sprite"/>
                                      <accessor name="buttonMode" access="readwrite" type="Boolean" declaredBy="flash.display::Sprite"/>
                                      <method name="swapChildrenAt" declaredBy="flash.display::DisplayObjectContainer" returnType="void">
                                        <parameter index="1" type="int" optional="false"/>
                                        <parameter index="2" type="int" optional="false"/>
                                      </method>
                                      <method name="swapChildren" declaredBy="flash.display::DisplayObjectContainer" returnType="void">
                                        <parameter index="1" type="flash.display::DisplayObject" optional="false"/>
                                        <parameter index="2" type="flash.display::DisplayObject" optional="false"/>
                                      </method>
                                      <method name="getChildByName" declaredBy="flash.display::DisplayObjectContainer" returnType="flash.display::DisplayObject">
                                        <parameter index="1" type="String" optional="false"/>
                                      </method>
                                      <accessor name="textSnapshot" access="readonly" type="flash.text::TextSnapshot" declaredBy="flash.display::DisplayObjectContainer"/>
                                      <method name="removeChildAt" declaredBy="flash.display::DisplayObjectContainer" returnType="flash.display::DisplayObject">
                                        <parameter index="1" type="int" optional="false"/>
                                      </method>
                                      <method name="removeChild" declaredBy="flash.display::DisplayObjectContainer" returnType="flash.display::DisplayObject">
                                        <parameter index="1" type="flash.display::DisplayObject" optional="false"/>
                                      </method>
                                      <method name="getChildIndex" declaredBy="flash.display::DisplayObjectContainer" returnType="int">
                                        <parameter index="1" type="flash.display::DisplayObject" optional="false"/>
                                      </method>
                                      <method name="getObjectsUnderPoint" declaredBy="flash.display::DisplayObjectContainer" returnType="Array">
                                        <parameter index="1" type="flash.geom::Point" optional="false"/>
                                      </method>
                                      <method name="addChildAt" declaredBy="flash.display::DisplayObjectContainer" returnType="flash.display::DisplayObject">
                                        <parameter index="1" type="flash.display::DisplayObject" optional="false"/>
                                        <parameter index="2" type="int" optional="false"/>
                                      </method>
                                      <method name="addChild" declaredBy="flash.display::DisplayObjectContainer" returnType="flash.display::DisplayObject">
                                        <parameter index="1" type="flash.display::DisplayObject" optional="false"/>
                                      </method>
                                      <accessor name="tabChildren" access="readwrite" type="Boolean" declaredBy="flash.display::DisplayObjectContainer"/>
                                      <method name="getChildAt" declaredBy="flash.display::DisplayObjectContainer" returnType="flash.display::DisplayObject">
                                        <parameter index="1" type="int" optional="false"/>
                                      </method>
                                      <accessor name="mouseChildren" access="readwrite" type="Boolean" declaredBy="flash.display::DisplayObjectContainer"/>
                                      <method name="setChildIndex" declaredBy="flash.display::DisplayObjectContainer" returnType="void">
                                        <parameter index="1" type="flash.display::DisplayObject" optional="false"/>
                                        <parameter index="2" type="int" optional="false"/>
                                      </method>
                                      <method name="areInaccessibleObjectsUnderPoint" declaredBy="flash.display::DisplayObjectContainer" returnType="Boolean">
                                        <parameter index="1" type="flash.geom::Point" optional="false"/>
                                      </method>
                                      <accessor name="numChildren" access="readonly" type="int" declaredBy="flash.display::DisplayObjectContainer"/>
                                      <method name="contains" declaredBy="flash.display::DisplayObjectContainer" returnType="Boolean">
                                        <parameter index="1" type="flash.display::DisplayObject" optional="false"/>
                                      </method>
                                      <accessor name="mouseEnabled" access="readwrite" type="Boolean" declaredBy="flash.display::InteractiveObject"/>
                                      <accessor name="tabIndex" access="readwrite" type="int" declaredBy="flash.display::InteractiveObject"/>
                                      <accessor name="accessibilityImplementation" access="readwrite" type="flash.accessibility::AccessibilityImplementation" declaredBy="flash.display::InteractiveObject">
                                        <metadata name="Inspectable">
                                          <arg key="environment" value="none"/>
                                        </metadata>
                                      </accessor>
                                      <accessor name="focusRect" access="readwrite" type="Object" declaredBy="flash.display::InteractiveObject"/>
                                      <accessor name="doubleClickEnabled" access="readwrite" type="Boolean" declaredBy="flash.display::InteractiveObject"/>
                                      <accessor name="contextMenu" access="readwrite" type="flash.ui::ContextMenu" declaredBy="flash.display::InteractiveObject"/>
                                      <accessor name="tabEnabled" access="readwrite" type="Boolean" declaredBy="flash.display::InteractiveObject"/>
                                      <accessor name="scale9Grid" access="readwrite" type="flash.geom::Rectangle" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="parent" access="readonly" type="flash.display::DisplayObjectContainer" declaredBy="flash.display::DisplayObject"/>
                                      <method name="hitTestObject" declaredBy="flash.display::DisplayObject" returnType="Boolean">
                                        <parameter index="1" type="flash.display::DisplayObject" optional="false"/>
                                      </method>
                                      <accessor name="stage" access="readonly" type="flash.display::Stage" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="width" access="readwrite" type="Number" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="accessibilityProperties" access="readwrite" type="flash.accessibility::AccessibilityProperties" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="scrollRect" access="readwrite" type="flash.geom::Rectangle" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="height" access="readwrite" type="Number" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="alpha" access="readwrite" type="Number" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="x" access="readwrite" type="Number" declaredBy="flash.display::DisplayObject"/>
                                      <method name="getBounds" declaredBy="flash.display::DisplayObject" returnType="flash.geom::Rectangle">
                                        <parameter index="1" type="flash.display::DisplayObject" optional="false"/>
                                      </method>
                                      <accessor name="y" access="readwrite" type="Number" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="opaqueBackground" access="readwrite" type="Object" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="cacheAsBitmap" access="readwrite" type="Boolean" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="visible" access="readwrite" type="Boolean" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="scaleX" access="readwrite" type="Number" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="mouseX" access="readonly" type="Number" declaredBy="flash.display::DisplayObject"/>
                                      <method name="hitTestPoint" declaredBy="flash.display::DisplayObject" returnType="Boolean">
                                        <parameter index="1" type="Number" optional="false"/>
                                        <parameter index="2" type="Number" optional="false"/>
                                        <parameter index="3" type="Boolean" optional="true"/>
                                      </method>
                                      <accessor name="scaleY" access="readwrite" type="Number" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="mouseY" access="readonly" type="Number" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="mask" access="readwrite" type="flash.display::DisplayObject" declaredBy="flash.display::DisplayObject"/>
                                      <method name="getRect" declaredBy="flash.display::DisplayObject" returnType="flash.geom::Rectangle">
                                        <parameter index="1" type="flash.display::DisplayObject" optional="false"/>
                                      </method>
                                      <accessor name="rotation" access="readwrite" type="Number" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="name" access="readwrite" type="String" declaredBy="flash.display::DisplayObject"/>
                                      <method name="localToGlobal" declaredBy="flash.display::DisplayObject" returnType="flash.geom::Point">
                                        <parameter index="1" type="flash.geom::Point" optional="false"/>
                                      </method>
                                      <method name="globalToLocal" declaredBy="flash.display::DisplayObject" returnType="flash.geom::Point">
                                        <parameter index="1" type="flash.geom::Point" optional="false"/>
                                      </method>
                                      <accessor name="transform" access="readwrite" type="flash.geom::Transform" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="blendMode" access="readwrite" type="String" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="root" access="readonly" type="flash.display::DisplayObject" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="filters" access="readwrite" type="Array" declaredBy="flash.display::DisplayObject"/>
                                      <accessor name="loaderInfo" access="readonly" type="flash.display::LoaderInfo" declaredBy="flash.display::DisplayObject"/>
                                      <method name="removeEventListener" declaredBy="flash.events::EventDispatcher" returnType="void">
                                        <parameter index="1" type="String" optional="false"/>
                                        <parameter index="2" type="Function" optional="false"/>
                                        <parameter index="3" type="Boolean" optional="true"/>
                                      </method>
                                      <method name="willTrigger" declaredBy="flash.events::EventDispatcher" returnType="Boolean">
                                        <parameter index="1" type="String" optional="false"/>
                                      </method>
                                      <method nTypeError: Error #1009: Cannot access a property or method of a null object reference.
                                      at edu.apollogrp.moviepostergenerator.view::MainView/moviePosterConfig()[H:\IDD\Working Folders\Brian Krainock\src\edu\apollogrp\moviepostergenerator\view\MainView.mxml:80]
                                      at edu.apollogrp.moviepostergenerator.view::MainView/init()[H:\IDD\Working Folders\Brian Krainock\src\edu\apollogrp\moviepostergenerator\view\MainView.mxml:58]
                                      at edu.apollogrp.moviepostergenerator.view::MainView/___MainView_Canvas1_creationComplete()[ H:\IDD\Working Folders\Brian Krainock\src\edu\apollogrp\moviepostergenerator\view\MainView.mxml:3]
                                      at flash.events::EventDispatcher/dispatchEventFunction()
                                      at flash.events::EventDispatcher/dispatchEvent()
                                      at mx.core::UIComponent/dispatchEvent()[C:\autobuild\galaga\frameworks\projects\framework\sr c\mx\core\UIComponent.as:9408]
                                      at mx.core::UIComponent/set initialized()[C:\autobuild\galaga\frameworks\projects\framework\src\mx\core\UIComponent.a s:1169]
                                      at mx.managers::LayoutManager/doPhasedInstantiatioame="addEventListener" declaredBy="flash.events::EventDispatcher" returnType="void">
                                        <parameter index="1" type="String" optional="false"/>
                                        <parameter index="2" type="Function" optional="false"/>
                                        <parameter index="3" type="Boolean" optional="true"/>
                                        <parameter index="4" type="int" optional="true"/>
                                        <parameter index="5" type="Boolean" optional="true"/>
                                      </method>
                                      <method name="dispatchEvent" declaredBy="flash.events::EventDispatcher" returnType="Boolean">
                                        <parameter index="1" type="flash.events::Event" optional="false"/>
                                      </method>
                                      <method name="hasEventListener" declaredBy="flash.events::EventDispatcher" returnType="Boolean">
                                        <parameter index="1" type="String" optional="false"/>
                                      </method>
                                    </factory>
                                  </type>

                                  • 14. Re: Accessing Flash MovieClips in Flex
                                    Flex harUI Adobe Employee

                                    You can see from the extendsclass list that the object is a Sprite and not a

                                    MovieClip.  Maybe if the MC has only one frame it gets imported as a Sprite?

                                    1 person found this helpful
                                    • 15. Re: Accessing Flash MovieClips in Flex
                                      BKUoP Level 1

                                      When I change everything from MovieClip to Sprite, as long as its wrapped in a UIComponent it displays.  But the same problem still exists, which is: When I try to reset the text property on a TextInput that is a child of this Sprite, Flex doesn't recognize the Sprite at all.  So I get a "Access of possibly undefined property comedyMC through...."  Despite the fact that I am declaring my comedyMC as a public var at the top of my Class.  I'm declaring it as a type Sprite.  Any ideas from anyone out there on how I can get Flex to recognize this child Sprite so I can access this TextInput?

                                      • 16. Re: Accessing Flash MovieClips in Flex
                                        Flex harUI Adobe Employee

                                        What is the full text of the error and the stacktrace?

                                        • 17. Re: Accessing Flash MovieClips in Flex
                                          BKUoP Level 1

                                          Error 1119: Access of possibly undefined property comedyMC through a reference with static type edu.apollogrp.moviepostergenerator.view:MoviePoster

                                           

                                          Sorry but I'm unfamiliar with what a stacktrace is.  If you let me know I'll be happy to provide

                                          • 18. Re: Accessing Flash MovieClips in Flex
                                            Flex harUI Adobe Employee

                                            The stacktrace is all the text following the error.

                                             

                                            The describetype dump was for a class called MainView_Comedy.  I did not see

                                            mention of a comedyMC in the text of the dump.  If you do a describetype

                                            dump on the MoviePoster class, it may or may not mention comedyMC.  If it

                                            isn't there, check the class definition to make sure the property is public.

                                            • 19. Re: Accessing Flash MovieClips in Flex
                                              -skitch- Level 1

                                              When exporting your symbol for Actionscript, try setting the base class to mx.flash.UIMovieClip

                                               

                                              Shows that it is a Flex component...I usually do this for skinclasses.

                                              • 20. Re: Accessing Flash MovieClips in Flex
                                                BKUoP Level 1

                                                @Flex harUI

                                                 

                                                did a describeType dump and its in there, and its type is flash.display.Sprite.  What I'm afraid of is the textInput I'm trying to get to was created (dynamic text field) in Flash, and is inside this Sprite.  My concern is what if by default the children of the Sprite aren't public, or visible when this Sprite is brought into flex...hence the reason why its not finding the textInput to allow me to change the text property.  Does anyone know what the default behavior is for this sort of thing and if they aren't public by default...is there a way in Flash to set it to a public instead of private property?

                                                 

                                                Btw, thx again Flex harUI for stickin' with me through this process.  Its def. been a learning experience for me 

                                                • 21. Re: Accessing Flash MovieClips in Flex
                                                  Flex harUI Adobe Employee

                                                  The author of the class has control over what outsiders can see.  I think

                                                  the default in Flash is public, but someone can certainly change it.  You

                                                  can't get to the internal TextField in Flex text controls either.

                                                   

                                                  There are no master keys or other ways of breaking and entering to get

                                                  access to properties.  However, because the display object tree is public

                                                  (via getChildAt()), you can generally access child display objects unless

                                                  the class author further guarded against that, which is rare.  However,

                                                  since you are accessing via child index, you there is a chance you'll grab

                                                  the wrong child.

                                                  • 22. Re: Accessing Flash MovieClips in Flex
                                                    BKUoP Level 1

                                                    After tracing it out, the textField I need to replace the text property is at index 2.  I must not be doing something right in my code because here's my code and the error I get.  I feel like I'm SO close, so hopefully we can wrap this up today.

                                                     

                                                    private function txtTitleChangeHandler(event:Event):void
                                                                {
                                                                    if (controlPanelsView.txtMovieTitle.text != "")
                                                                    {
                                                                        //trace("Change event Handler");
                                                                        //trace(currentMovie.movieSprite.getChildAt(2));
                                                                        currentMovie.movieSprite.getChildAt(2).text = controlPanelsView.txtMovieTitle.text;
                                                                    }else
                                                                    {
                                                                        trace("shows text input is empty");
                                                                        return;
                                                                    }
                                                                }

                                                     

                                                     

                                                    Error 1119: Access of possibly undefined property text through a reference with static type flash.display:DisplayObject.

                                                     

                                                    When I trace it out, as seen in the line above (that's currently remmed out) I get this in the trace:[object TextField]

                                                     

                                                    so I know its the text field I'm trying to access.

                                                    • 23. Re: Accessing Flash MovieClips in Flex
                                                      Flex harUI Adobe Employee

                                                      TextField(currentMovie.movieSprite.getChildAt(2)).text =

                                                      controlPanelsView.txtMovieTitle.text;

                                                       

                                                      • 24. Re: Accessing Flash MovieClips in Flex
                                                        BKUoP Level 1

                                                        Ha Ha it worked!  Thank you Flex harUI!

                                                         

                                                        So is the TextField(.....).text just creating a temp variable?  It worked, but I'd like to be sure I understand why, and what's going on here so I can implement in the future without having to get back on the forums again.

                                                         

                                                        Thanks again.

                                                        • 25. Re: Accessing Flash MovieClips in Flex
                                                          Flex harUI Adobe Employee

                                                          SomeClass(someobj) does two things.  It tells the compiler to treat the

                                                          object as in instance of subclass when determining which properties are

                                                          available, and it causes the compiler to add code to check that the object

                                                          is of that type at runtime.  I don't think of it as a temporary variable

                                                          although the runtime might use one.

                                                          • 26. Re: Accessing Flash MovieClips in Flex
                                                            BKUoP Level 1

                                                            Ah ok, I get it.

                                                             

                                                            Thanks again for all your help and guidance, I definitely understand the intricacies of using Flash and Flex together now...it was a great learning experience.