views:

2688

answers:

4

I'm using the Flex 3 SDK and the free FlashDevelop IDE.

As I don't have FlexBuilder or Flash CS4 Professional I cannot make MovieClips graphically.

So instead I want to create a simple MovieClip using code or MXML. For example, lets say I want to create a MovieClip with 3 frames, and load a bitmap into each frame to create a simple animation.

Is this possible? I've had a good google around and the only examples I can find are of loading existing MovieClips and adding them to a stage.

+1  A: 

You can create a movieclip with this simple code:

var mc:MovieClip = new MovieClip();
stage.addChild(mc);

That is of cause just and empty movieclip, you can draw on it with graphics property (see here).

As far as I know there is no way to create frame with actionscript. Though there might be some undocumented methods. There are some functions that do not appear in the documentation (like the addFrameScript method).

I would say the best way (if you absolutly can not use the Flash CS4), would be to have a series of Loader objects, and the hide and show them on every in sequence. Just put them in an array and listen for the enterFrame event. You can load in the bitmaps in the Loader objects.

If you use the links and checkout the examples in the documentation, I think you should be able to figure it out.

Lillemanden
A: 

As far as I've seen, there is no easy way to create a MovieClip in Flex which behaves in a way one might see as comparable to Flash's implementation MovieClip. But I don't think you really want a MovieClip to begin with. Flex does not really play well with non-flex objects. Yes, it is possible to add something to a UIComponent, but you are much better off working withing the Flex framework than doing workarounds.

I would use the mx:Image tag to load your images. It is generally the cleanest way to load an image into Flex. It will let you embed the object into the SWF at compile time, which means that you will not have to point to an outside file. I will caution about having too many embedded graphics -- that will kill your download time and possibly your performance.

If you are only interested in having an animation move or re-size, then I would use the Move and Resize objects which are native Flex Tweens.

Christopher W. Allen-Poole
A: 

Your best option might be to extend the UIComponent class, add a MovieClip as a child-component, and apply the settings from MXML via proxy. e.g.,

public function set movieFrames(value:Array):void {
   for each(var b:Bitmap in value) {
      //add bitmap to _movieclip object.
   }
}
Glenn
but how do you control which frame the bitmap will end up in?
codeulike
Depends on what you mean by "frame". Within flex, you can probably accomplish what you need using either timers or the ENTER_FRAME event, and a counter that marks which image you want to show. http://www.nivas.hr/blog/2006/11/27/as3-kitchen-timer-and-enter_frame/#more-101On each frame, or timer tick: imgCounter = (++imgCounter) % bitmapList.length displayedBitmap = bitmapList[imgCounter];Something like that...
Glenn
A: 

You want a Sprite not a MovieClip. And use time instead of frames. There's a Timer class and a getTimer() function. Use them.

  1. create a class that extends/implements Sprite.
  2. Add a Loader class.
  3. Google it exactly how it's done. (flashtuts.com or sth like that).