views:

42

answers:

1

I have some older AS2-style Haxe code which uses flash.Lib.Current.CreateEmptyMovieClip() to create a slideshow of disk-based images. It creates a new clip for holding each image and simply fades each image in and out with alpha levels.

Compiling it with -swf -swf-version 8 creates an SWF file fine and this works in the browser.

However, I'm in the process to converting this over to -swf9 and I find that the MovieClip no longer has that method.

How do you load up a series of images with Haxe (AS3-style)?

The code, for what it's worth, is along these lines:

static function main() {
  mc = flash.Lib.current;
  var clip : MovieClip;

  clip = mc.createEmptyMovieClip ("clip_000", mc.getNextHighestDepth());
  clip.loadMovie ("demo_img000.jpg");

  : : :
+6  A: 

You can just create a new display object w/o linking it to a clip in the library like this:

var sprite:Sprite = new Sprite() // -- creates a sprite
var clip:MovieClip = new MovieClip() // -- creates a movie clip

You can then add it to another display object by using the addChild() method:

myOtherClip.addChild( sprite )

The above line will add the new clip to the top of the display list, just like using getNextHighestDepth().

If you want to add a clip a depth between two other clips you can use:

myOtherClip.addChildAt( movieClip, 2 ); // -- adds a clip at 2 levels up from 0

As for loading an image, loadMovie does not exist in AS3. You need to use the Loader and URLRequest objects like this:

var loader:Loader = new Loader();
var request:URLRequest = new URLRequest( 'path_to_my_image.jpg' );
loader.addEventListener( Event.COMPLETE, onLoadComplete );
loader.load( request );

function onLoadComplete( event:Event ):void
{
     if( loader.content ){
         clip.addChild( loader.content )
     }
}
jeremynealbrown
This is one of the things that's *much* nicer in AS3.
Herms
I'll no doubt accept this answer since it appears to work okay (at least preliminarily). One thing I'm not getting - how to you specify where the sprite/clip goes on the main clip? In other words, `x=mc.createTextField(name,mc.getHighestDepth(),0,300,400,20)` specifies where the field goes and its size. How do you do this with just `x = new TextField()`?
paxdiablo
clip.x = 300;clip.y = 400;parentClip.addChild( clip )
jeremynealbrown