Flixel Forums

development => releases => Topic started by: wg/funstorm on Wed, Sep 28, 2011

Title: FlxMovieClip
Post by: wg/funstorm on Wed, Sep 28, 2011
FlxMovieClip (http://www.funstormgames.com/blog/2011/09/flxmovieclip/)

With FlxMovieClip you can draw a Flash MovieClip just like an FlxSprite (with a couple exceptions).
Using FlxMovieClips is more processing intensive than the other methods. Donít use this if you can avoid it!

Basic Usage

Code: [Select]
var fmc:FlxMovieClip = new FlxMovieClip(x,y);
fmc.loadMovieClip(movieclip, width, height);
fmc.isPlaying = true;

Demo / Download / Instructions

http://www.funstormgames.com/blog/2011/09/flxmovieclip/ (http://www.funstormgames.com/blog/2011/09/flxmovieclip/)


What's the point of this?
- To draw a Flash MovieClip as an FlxSprite, so you can use it in Flixel like any other FlxSprite.

Should I use this instead of FlxSprites or FlxG.stage.addChild()/addChildAt()?
- Using FlxMovieClips is more processing intensive than the other methods. Don't use this if you can avoid it!

Why not just use FlxSprites instead of MovieClips?
- It's true that MovieClips can be rendered as sprite sheets and imported into Flixel. This should be the first thing you try!
- However, sometimes FlxSprites just don't meet the requirements - e.g. complicated menus with lots of animations, or long high-quality cutscenes that are simply too large to render as a sprite sheet.

Why not just use FlxG.stage.addChild()/addChildAt()?
- It's true that addChild can be used to draw a MovieClip on top of or below the Flixel camera. This should be the second thing you try!
- However, sometimes addChild just doesn't meet the requirements - e.g. if you want the Flixel cursor to appear on top, or draw the MovieClip at a specific order within the Flixel display list.

Can I really do everything I can do with a Flash MovieClip with an FlxSprite?
- No! Some method and properties are unsupported.
- Supported: x, y, angle, scale, offset, velocity, acceleration, antialiasing, visible, flash movieclip animations
- Unsupported: alpha, blend, replaceColor, stamp, drawLine, fill, active, flixel animations


This is my first time ever releasing code to a community! Let me know what you think! Hope I didn't do anything stupid super obvious :P
Title: Re: FlxMovieClip
Post by: test84 on Mon, Apr 2, 2012
It's fantastic! I can't believe how it is easy to use and works great!

BTW, I'm not that familiar with regular Flash, so would you please kindly tell me how to make a .SWC file out of a regular .FLA ? Like how to make a movieclip.

My artist made a cutscene with flash and I have it's FLA and SWF files but I think I have to make it into a MovieClip and export as SWC so I can get it to work inside flixel, right? How so?

I tried to open your Smiley.FLA but it's created with CS5.5 and my Flash is CS 5 so it won't open it :/

I tried this already: I selected the animation and chose Conver to Symbol, choose movieclip and chose a linkage name, but in the publish menu, export to SWC is disabled. I was not targetting FP10 and AS3.

How I can make my movieclip so it can be "play" ed? I realized I just converted the first frame into MC but the FLA file consist of frame and keyframes, how I can move them into the movieclip as well? http://livedocs.adobe.com/flash/9.0/UsingFlash/help.html?content=WSd60f23110762d6b883b18f10cb1fe1af6-7de8.html (please correct me if I have to do another method for your FlxMovieClip class specifically)

1- I have a 2x zoom on my game that I set in the flixel's constructor but apparently the MC that I load doesn't get zoomed, is that right? I see only parts of my MC in the game.

2- And I believe it's been played faster than it does in the Flash, is it like this?

3- I also tried right click on the MC in the Flash's library and "export as swc", didn't get noticeable different results.

4- I believe setting x and y position are kinda buggy, at least it is in my case and it can be me because I'm not sure about creating MC but if I put x and y of my mc to zero, it's not visible but if I put both of them to 1, I can see 3/4 of my mc. (but since my movie clip is not shown entirely, as I stated in number 1, these can be related).

please note that my MC is supposed to be fullscreen, that's why I'm putting 0 to x and y of it.

(it can be related to some kind of origin that I vaguely remember from old flash days of mine that there was a point that you would set it for 0,0 of your MC)
Title: Re: FlxMovieClip
Post by: wg/funstorm on Wed, Apr 4, 2012
1. Making a swc - it's under your publish settings. Just tick the box next to swc, I think its near swf. Then right click it in flash develop and select add to library. Then you can access any movieclips by name that are in the fla file as long as they have been set up to export for actionscript in their properties.

2. Zoom - I have no idea. Try it out!

3. Framerate. It plays at the framerate of your flixel project. So if you want to see it at the same speed, set the stage framerate in flash to what you have in the flixel game. I don't think its possible to set the framerate of individual movieclips (unless you write some code that manually advances through frames). But you can change the framerate of the entire stage so maybe if its just for cutscenes what I've done in the past is change the stage fps for cutscenes and then back to normal for gameplay.

4. Dunno never tried

5. In Flash, when you open the movieclip you see a little + symbol. That's 0,0 for the movieclip. Any graphics should be right & down of 0,0. Anything that is higher than that +, or further to the left, will get cut off. You have to imagine that the movieclip is being stamped onto an flxsprite. And since the FlxSprite size starts at 0,0 anything before then will get cut off. If you are only seeing half, it sounds like your movieclip graphics are centered on the middle. Just move them and you should be fine.
Title: Re: FlxMovieClip
Post by: test84 on Wed, Apr 4, 2012
Thank you for the replies.

1- Thanks.

2- It's probably due to that origin that you described as it's apparently solved now.

3- Very important, thanks. I can change the scene's FPS with FlxG.SetFrameRate?

4- I'm more positive on this. If I don't set it's x and y to 1, it doesn't show anything.

5- You mean the "+" sign at the middle of the screen? So any movieclip you design should be on the bottom right quarter of the screen?! What if you want to have something full screen? Like a cutscene?

6- As putting FlixelMovieClip's x and y to 1 is strange to me, I tried to give this offset in the Flash and not in the flixel, same result: doesn't show anything. It has to be at least 1. I think you didn't face such thing because at least your test was not about a fullscreen movie clip. I however have no idea if you've used it in any of your games.

7- I hope it's not rude of me to ask, but did you try this in a game that you've published? I mean how reliable and safe it is in your experience?
Title: Re: FlxMovieClip
Post by: test84 on Thu, Apr 5, 2012
8- I tried the x, y bug that I suspected with your example that you supplied with FlxMovieClip: if you remove the lines that you set it's x and y to stage's middle points, it won't show at all but if you set it's x and y to 1, you'll see it.

9- You said in your web page that
Code: [Select]
fmc.loadMovieClip(movieclip, width, height, true); does this: "To create a new looping FlxMovieClip and add it to the state" but I think it doesn't "add it to the state". You may have updated the code but blog post remained unchanged or I'm wrong.

10- And in debug mode of flixel, I can't see a bounding box for moveclips, maybe something is wrong.
Title: Re: FlxMovieClip
Post by: wg/funstorm on Sun, Apr 8, 2012
Framerate... I can't remember the name of the method. You'll have to take a look around and see what works. I copied the method used in the focus lost screen where fps is decreased.

Fullscreen... if you want it fullscreen just position your FlxMovieclip at 0,0 and make it the same width/height as your game. It's similar to making a fullscreen FlxSprite. Anything that would be left/up of 0,0 would be cut off as its not on screen.

X/Y 1... Really not sure what's going on that would cause you to not have anything show up unless they're set to 1. All I can say is I never had to do it and I've used it for fullscreen stuff just fine. Just make sure all your movieclip content in flash is position down+right of the + symbol.

I've used it in every single one of my 6 flixel games with success. It's not perfect, I usually end up finding something I want to tweak but the basics are there. Of course I don't provide any sort of guarantee that it will work - use at your own risk. If you find a bug you can always try and fix it and post the solution :) For example the debug bounding boxes I know don't work. Feel free to take a look at FlxSprite to see how it's done and copy the method.
Title: Re: FlxMovieClip
Post by: test84 on Sun, Apr 8, 2012
Thanks wg/funstorm,

It's strange that you used it for fulscreen and never had to change that x and y. Of course setting two member properties is nothing, what worries me is this could be a symptom of another problem.

Do you set your "register" matrix thingy in F8 menu of Flash to up left when you want to create a movieclip? Or oyu manually set it's x and y to zero? or do you set them to 1?

One more thing, does it work for moveclips that have other movieclips inside them?
Title: Re: FlxMovieClip
Post by: Ramontique on Thu, Jul 5, 2012
Does this mean that text in an FlxMovieClip is select-able?
Title: Re: FlxMovieClip
Post by: test84 on Wed, Aug 22, 2012
Is there a bug in playing sounds that are embedded in the movie clips? Because when I play my movieclip and I change state, the music is looping in the background.
(And I didn't specify "loop" arguement to be true in the FlxMovieClip's c'tor, this happens after the state change)
Title: Re: FlxMovieClip
Post by: auriplane on Wed, Aug 22, 2012
I think I had this problem with a sponsor logo.  I think it was AS2, which meant I could embed it from AS3, but not call any functions or set any variables on it.  I only "solved" this problem by asking my friend with the Flash IDE to edit it and keep the audio from looping.  (He had a site lock with the same sponsor, luckily, so he already had the logo.)

I was panicking a little under the time pressure, so I guess I'm not totally sure what was going on.  So this account could be mistaken :/
Title: Re: FlxMovieClip
Post by: test84 on Wed, Aug 22, 2012
Thanks but we made the movieclip ourselves and added sound to it, how we can stop it from looping?

And why it doesn't get deleted when I change state?! Perhaps it waits for GC?
Title: Re: FlxMovieClip
Post by: wg/funstorm on Wed, Aug 22, 2012
Heh interesting I never actually tried it with sounds since I always just thought of it as way to draw to an FlxSprite. Did you try setting myFlxMc.isPlaying = false before exiting the stage? That calls the actionscript stop() function on the movieclip and if even that doesn't work then I dunno!

Personally I play my sounds separately from the flxmc but I can see why that would be a neat way to do it (if you can get it to work).

How do you mean it doesn't get deleted? Does it stay in memory? Or does it stay on screen?

You could try remove()ing it from your state, then it shouldn't draw anymore. You can also call destroy() on it which sets the movieclip = null which should also stop it from drawing.
Title: Re: FlxMovieClip
Post by: RAMeyer19 on Sun, Apr 28, 2013
I'm a bit of a .fla Noob so bear with me on this, but...

Looking at the demo I'm still confused at exactly how to embed a movieclip and reference it in code.

If I do a normal embed as in something like this I get a compile error:
[Embed(source = "../media/CountDownAnimationTest.swc")]public var CountDownAnimTest:Class;

Do I just need to have it somewhere in my folder structure, and then how do I reference it?

Also when trying to just compile the sample project provided I get the compile error about MC_Smiley() being an undefined method? How do I link that to the actual .swc or .fla?

Thank you so much.

And I'm using Flashbuilder 4.6 if that matters.

UPDATE: Answering my own question -

In Flashbuilder I had to right-click the project, select ActionScript Build PAth, then Library Path, then click Add SWC and browse to the .swc file.

Thanks again for this functionality.