8 Replies Latest reply on May 16, 2011 10:43 PM by Madhav Subedi

    can we control movie clips in the embedded swf?

    Madhav Subedi Level 4


      a swf file is embedded in flex ( i also have fla, so if any changes in fla required, i can do it ). from flex, i need to access the movie clips in swf:

      • change color of only one movie clip
      • add event listeners to the movie clip


      any help, if possible an example/link, is much appriciated.

        • 1. Re: can we control movie clips in the embedded swf?
          markerline Level 4

          I don't know anything about Flex filetypes but I know that in ActionScript 3.0 you can externalize the AS files so that your classes can call functions within a master Class Constructor file that controls aspects of the dynamic SWF.  What that means essentially is since AS files are text files you can change and update them dynamically just as you would change an HTML file dynamically.  I don't know exactly how this is done or what type of automation script you would run to always update and change the AS file but I am positive it can be done.  So you don't need to reauthor your FLA each time, you can just update the AS file.



          Correction:::  Once an SWF is generated it no longer calls upon the AS file so you would have to generate a dynamic SWF that looks for XML data updates.




          You might also be able to access some SWF properties through javascript or through an XML database..essentially the same way you would change an HTML file since XML is similar to HTML.


          But I am hoping someone in the Flex knowledgebase can answer your question more directly.



          • 2. Re: can we control movie clips in the embedded swf?
            Level 2

            Flash cs4 or 5?  As3. ??  Does it load at least

            • 3. Re: can we control movie clips in the embedded swf?
              markerline Level 4

              As I stated I don't know anything about the Flex SDK or authoring environment so I mentioned ActionScript because that is the scripting language for Flash as you are well aware of I'm sure.  But I realized once I had written all of that that I remembered what I was told--once an SWF is compiled it will no longer look to the ActionScript AS 3.0 file for data.  That has to be done through XML (or JavaScript within the embedded HTML/SWF combo).

              • 4. Re: can we control movie clips in the embedded swf?
                Flex harUI Adobe Employee

                See past threads about MovieClipLoaderAsset.  There is a way to get at the

                internal SWF that way.

                • 5. Re: can we control movie clips in the embedded swf?
                  markerline Level 4

                  Hi.  I see this post:


                  and it seems like a very powerful tool that is not accessible outside of Flex since it has the mx.core declaration .  What one responder posted looked like XML syntax but I think it is Flex syntax.  Is that to say that Flex is a language based on XML and is written with tags in a similar fashion?

                  • 6. Re: can we control movie clips in the embedded swf?
                    Level 2

                    sadly yes lol. seriously are you not already a Flex developer ?


                    if not, the main app file is pretty much markup. you can do a lot of powerful thing in markup like access properties and set up the callback / event handlers, and set powerful binding expressions. it is very similar to Silverlight. THe gurus there just bang stuff out, the whole app, in markup.


                    but you can use embedded actionscript in the markup or reference external AS classes or files. The markup can be quite minimal if that is your taste and it certainly is mine

                    • 7. Re: can we control movie clips in the embedded swf?
                      Level 2

                      working example:




                      the textarea thingy is actually a Flash CS5 swf that contains a textfield. the swf is loaded into an FB4.5 main app Spark/SwfLoader. here is the Flash code:



                      just create a new fla and set its File / Publish Setting / Flash / Script / Settings / Document Class = control_me


                      ... so it knows what to run.


                      here is FB4.5 app that controls it:



                      when you hit the button which is in fb4.5, it adds text to the loaded swf's textfield


                      so you are running a fb4.5 html wrapper that loads an fb4.5 swf that loads and controls a flash swf. so what you need to do is in your stuff just control the videoplayer or what not and not a text area. but as you can see it commands it around.

                      1 person found this helpful
                      • 8. Re: can we control movie clips in the embedded swf?
                        Madhav Subedi Level 4

                        Thanks all for your help, while i was offline to the internet, i wanted to tryout myself, and generated something by chance which works....


                        <?xml version="1.0" encoding="utf-8"?>
                        <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                                    import com.google.maps.Color;
                                    import mx.controls.Alert;
                                    private function hideit(child_name:String):void
                                        var mc:MovieClip = MovieClip(fl.content);
                                        mc.getChildByName(child_name).visible = false;
                                    private function showit(child_name:String):void
                                        var mc:MovieClip = MovieClip(fl.content);
                                        mc.getChildByName(child_name).visible = true;
                                    private function changecolor(child_name:String):void
                                        var clr1:uint;
                                        clr1 = child_name == 'btn_one' ? c1.selectedColor : c2.selectedColor;
                                        var mc:MovieClip = MovieClip(fl.content);
                            <mx:SWFLoader source="test.swf"
                            <!-- is it true that EMBEDDING will not allow to access the movieclips inside? -->
                                <mx:Button click="hideit('btn_one')"
                                <mx:Button click="hideit('btn_two')"
                                <mx:Button click="showit('btn_one')"
                                <mx:Button click="showit('btn_two')"
                                <mx:ColorPicker id="c1"
                                <mx:ColorPicker id="c2"


                        i have almost NO-KNOWLEDGE about flash, but what i tried is

                        - use pen tool to create two shapes

                        - use fill color in both

                        - right click > convert to symbol > to movie clip ( for each of those shapes )

                        - select, click on properties, provide instance names ( btn_one / btn_two )

                        - press F9 ( actions ), select frame1( it is as3 project ), and provide following code:


                        import flash.geom.ColorTransform;
                        import flash.display.MovieClip;
                        btn_one.buttonMode = true;
                        btn_two.buttonMode = true;
                        function changeColor(childname:String,clr:uint)
                             var a:MovieClip = MovieClip(getChildByName(childname));
                             var color_transform:ColorTransform=a.transform.colorTransform;


                        and it worked...


                        now WHAT DID NOT WORK in flex is:


                        var mc:MovieClip = MovieClip(fl.content);
                        var c1:MovieClip = mc.getChildByName('btn_one') as MovieClip;
                        c1.addEventListener(MouseEvent.CLICK, function():void
                        (mc.getChildByName('btn_two') as MovieClip).addEventListener(MouseEvent.CLICK, function():void