Cloning a MovieClip for a non-Flash target

Hi,

I’m new to OpenFL. I’m actually porting an old Flash project to haxe and all my assets are in the swf format.
I need to have multiple instances of the same MovieClip on stage but behaving differently (different alphas to do transition effects).

This is the solution I have working for a flash target :

public function cloneMovieClip()
{
        var bytes:ByteArray = previousLoader.content.loaderInfo.bytes;
        Loader loader = new Loader();	
	var lc : LoaderContext = new LoaderContext();
	lc.allowCodeImport = true;
	loader.loadBytes(bytes,lc);
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleted);
}

Does this work with a non-flash target too (windows/html5) ?
I use the SWF library to load swfs for windows and not the Flash Loader class anymore. How could I get the bytes from an existing MovieClip or from a loaded Swf library ?
Should I load my swfs using the Assets.loadBytes() function instead ? Where could I find an example or a sample showing how to use that function ?

Thank you very much.

You should be able to use Assets.getMovieClip or use new ClassFromSWF () multiple times, so that you can instantiate the same clip more than once. Give it a try, and let me know how it works for you

Thank you very much for your answer.

After testing it on a sample project (not on my main project) the multiple use of Assets.getMovieClip() works on windows and html5 targets but not on Flash targets. It doesn’t really matter : I already have a working Flash cloning code. I’ll use conditional compilation.

I still have problems loading swfs for non-flash targets, though. Should I explain the issue here or on another topic ?

If you are able to, maybe using <library path="library.swf" type="swflite" /> would be proper. This uses our “SWFLite” format instead of traditional SWF loading in Flash as well, which should allow multiple instances of the same root MovieClip. Another approach is to mark a symbol in your library as “Export for ActionScript” with a custom class name, this can be used when doing Assets.getMovieClip by passing the name of your SWF library, followed by a colon and the name of the exported symbol, like “library:MyExportedMovieClipName”, if you generate="true" you can also use new MyExportedMovieClipName () and bypass Assets.getMovieClip entirely

As you probably can see, the SWF library is separate from OpenFL, and is compile-time. It is not quite designed for runtime loading of additional SWFLite content

I tihnk that we may look at integrating it in the future, so that OpenFL has built-in support for SWFLite format content, and we can derive a runtime method of loading that uses openfl.display.Loader – that would be neat :slight_smile:

I have a problem with a swf animation that weighs 2 Mo with non-flash targets. I just need to play it using movieClip.gotoAndPlay(1). I opened it this way :

Assets.loadLibrary ("libraryName", function (_) 
{
	var clip:MovieClip = Assets.getMovieClip ("libraryName:");
	addChild(clip);
	clip.gotoAndPlay(1);
});

I just have a blank screen instead. Is there a way to fix this problem or a workaround ?

Can you tell if it uses SWFLite? What OpenFL version are you using? There’s also the possibility that there is an issue with support for this animation, currently, our support seems to work better with MovieClips than raw shapes on keyframes

Thanks

I use swflite. I just upgraded Haxelib and I use version 4.0.1 of OpenFL and version 2.2.2 of Swf lib. The animation is just a plain video file. Would it be easier to load it as a video file ? I can send you my sample project with the file if you want.

Oh, I’m not actually sure how video would behave. Are you sure Flash Player is using SWFLite? I don’t think SWFLite supports video?

That is how my “project.xml” looks like :

        <haxelib name="openfl" />
	<haxelib name="swf" />
	
	<!-- assets -->
	<library path="assets/library.swf" id="library" type="swflite"/>

I have other swfs appearing on screen with swflite but not this one, which is basically a flv video, created with After Effects, wrapped inside a swf. It doesn’t work with the "swf’ type either (on non-flash targets). Do you have any idea to make it work ?

I think you’ll have to load it as a SWF at runtime on the Flash target, and use the same bytes trick to clone. We support HTML5 video, but that would need a different file format. We don’t have official video support for native at the moment

Ok. Thanks. I was looking for an Android and Windows version. But I guess I’ll have to stick to AIR.

Video support is planned, and if you want, we can consider adding AIR support, again, to the tools. It would look like:

openfl test air

Sorry. I didn’t quite get that last part. Are those compilation options ? Actually, I use FlashDevelop : should I add a “Custom command” to my compilation ?

Some years ago (five or six?) I made an AIR target for what later become Lime and OpenFL.

We could support this today with a bit of work. AIR targeting is a Flash build with a little extra packaging. If there’s an interest or demand for it, we could look at doing AIR builds again, allowing support for openfl test air just as you do openfl test windows, or in FlashDevelop terms, using OpenFL, the target drop-down could hold “air” as well as “flash” or “html5”

This is not supported at this moment, but it could be. That’s why I was asking

It was a misunderstanding : I didn’t say I needed you to add an AIR target but that if I can’t make Haxe work I’ll go back to Adobe AIR to get my “.exe” and my “.apk”. Actually I cleaned up my code while transferring my sources from “as3” to “haxe” so I would really like to keep working with haxe.

I think that instead of adding an AIR export it would be more important to improve the compatibility of the non-flash exports with “swf”. The two issues I have right now is that, the swf library can’t play a flash animation and that it can’t access the scenes with :
gotoAndPlay(index:Int, scene:String)

But I imagine you’re already working on all that.

I only mentioned AIR, because it’s low-hanging fruit we could possibly enable

As for other target support for animation, this is supported, but I think there may be some issues with shape-based animation, rather than animating MovieClip symbols

We do not support scenes at the moment, though this would be a nice improvement to the SWF support

Ok. Let’s try it another way : what formats works well with OpenFL that I could easily export my swf assets to ? Svg ?

If you’re using Flash CS6 or CC, you can export a spritesheet, then use the spritesheet to make a Tilemap. (An importer is in the works, but for now, you’ll have to set up the Tilemap yourself.)

If you have an older version of Flash (now Adobe Animate) I’ve used the Zoe application from gskinner.com to make spritesheets from swfs in the past.