Question

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");

  : : :
Was it helpful?

Solution

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 )
     }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top