Home > Uncategorized > Flex: working with MovieClips

Flex: working with MovieClips

You do not do everything with Flex components, especially if you develop games or cool interfaces. You often need to load SWF files and use the MovieClips inside them. A previous article talks about Instantiating and displaying MovieClips from loaded SWF.

Here are a few considerations when loading MovieClips into Flex:

  • If you embed a symbol, you will lose all timeline actions. Embed the whole SWF instead.
  •  

  • If you have a stop on the first frame of a multi-frame MovieClip, it might never execute. Add the action on the second frame.
  •  

  • When you say gotoAndStop (or gotoAndPlay), you cannot immediately reference the children on that frame. You have 3 choices:
    •   

    • Use stage.invalidate() and listen to RENDER events
    •  

    • Listen to ADDED events and check if the target of the event is the object that you need.
    •  

    • Forget about frames and do like Flex intended: one symbol per MovieClip state (button states for example)
    •  

  •  

  • If your MovieClip is 1-frame long, it will still loop indefinitely, consuming precious resources. Use stop() on the first frame.
  •  

  • When you use the addChild method with the MovieClip, the clip will not be copied. It will be removed from its previous parent (firing the REMOVED_FROM_STAGE event) and then added to the new parent.
  •  

  • You cannot duplicate a MovieClip. If you want to be able to create multiple instances, link these MovieClips in you SWFlibrary and instantiate as many as you want.
  •  

  • A MovieClip cannot be added directly to Flex containers. Add it as a child of a SWFLoader or an Image and add that control.
  •  

  • The Loader class is a DisplayObject but has trouble resizing itself. You can always grab the loader.content as a MovieClip and add it where you need it.
  •  

Tags: ,
  1. Manimaran
    April 10th, 2009 at 05:49 | #1

    Dear Friend,

    I added the loader.content as MovieClip in my Flex application canvas(myCanvas.rawChildren.addChild(myMC)), but i cannot control this MC by getChidrenByName(), please help me to do this.

    Thanks,
    Manimaran.

  2. April 10th, 2009 at 20:33 | #2

    If you use myCanvas.rawChildren.getChildByName(“myMC”), don’t forget to actually name your clip: myMC.name = “myMC”.
    getChildByName() does not look for variable names, but for the “name” property.

  3. sanhita
    November 12th, 2009 at 05:00 | #3

    I am Action Script Programmer. I am finding flex very complex & different from AS 3.0. Please help me with some tutorial where i can see difference between AS 3.0 & Flex AS

  4. November 15th, 2009 at 16:52 | #4

    sanhita, Flex is not a programming language. It is a framework for AS3. A quick search in Google yielded the following result: http://www.adobe.com/devnet/flex/videotraining/

    I hope that helps.

  5. Philou
    December 18th, 2009 at 12:30 | #5

    Hi Anna,

    I’m wrapping an swf created by Indesign in a flex application in order to add some extra buttons and use the \full screen\ feature. I would like to access some components inside the swf created by Indesign and am doing so already successfully with some named buttons. The Indesingn.swf has 5 frames (=5 spreads) and the named buttons are placed on spread 1 = frame 1.

    Here is what that looks like:

    var myMovieClip:MovieClip = MovieClip(mySWFLoader.content);
    var o:Object = Object(myMovieClip.getChildAt(0));
    var myIndesignButton:DisplayObject = o.getChildByName(‘buttonNamedInsideIndesign’);

    However, I would like to select other unnamed elements as well. Specifically I regret that the text of my finished flash animation is not selectable and available for copy&paste, so I would like to loop through the movie elements and if they are Text components, then I would like to set their \selectable\ property to true.

    Well, maybe my thinking is along the wrong lines, but even when I debug my flex application in eclipse, I cannot find the elements of my loaded Indesign swf anywhere inside the MovieClip object.

    Maybe you can give me a hint as to where I should look?

    Many thanks ind advance!
    Philou

  6. December 19th, 2009 at 07:27 | #6

    Hi, I am trying to create Flash Files on the fly. Can I do this using MovieClip ? Example application toufee.com Basically design a Flash Studio where the User can generate screens and objects with Effects. Can I achieve it using ActionScript and Flex. Please advise, thanks.

  7. ananth
    February 24th, 2012 at 09:12 | #7

    hi, i’m using video display control to take snapshot in flex4, and i wan to know how to record video through webcam and save in desire location in my local machine. whats the data type that i must use to save video clip in flex…….. then how can i get video from video display if user clicks save button………….

  1. No trackbacks yet.