I have a flash movieclip with retina resolution (about 200 frames) and some Action Script inside. I would like to use stage3d to get a performance boost. Is this possible just to add the movieclip to the stage3d stage without losing Action Script?
-
Do you have any code? This is a programming Q&A. See: http://stackoverflow.com/help/on-topic – Jean-François Côté Oct 07 '13 at 17:05
2 Answers
Short answer: No.
Long answer: Not exactly. ActionScript still executes in the same way regardless of your output. However, if you have content that you want rendered in the GPU, you need it decoupled from ActionScript code. You would have to have the same movieclip being executed and then all frames being sent to the GPU on the fly. This would be a massive resource hog - the GPU is great when rendering things, but you have to get your data (your "textures") there and this takes time. This upload to the GPU is complicated and can be a real bottleneck - certainly not something you should do every frame. And in that case you'd still need to draw() the movie anyway, so any performance gain during the final blitting would be moot.
IF your animation is small and short enough, you can render every frame to the same single bitmap as a tiled animation (like a sprite sheet). You then upload this massive image (up to 2048x2048, in most cases, or 4096x4096 in newer GPUs) to the hardware and then change the "frame" by changing the (UV) mapping coordinates. This is by far the fastest way to play an animation in Flash. But like stated, it requires that all frames be composed into the same image (on-the-fly or not), and uploaded once. With 200 frames, your animation would have to be of dimensions of 146x146 (more or less) for this to be possible, so it can be complicated (you're need more spritesheets).
You could obviously have one texture per frame too. That'd be a little bit more annoying for loading but it would work. You could then use something like Starling's MovieClip to have it play. But then again your ActionScript would be lost - you'd need to re-add them to your code somehow, by constantly checking the frame for example.
Another solution may be having your animation as a video and using StageVideo instead. It's super best and more suited for complex content being animated.
TL;DR: hardware acceleration is great in Flash, but by definition it only works in some circumstances. Some things are just better handled by Flash.

- 10,130
- 3
- 38
- 56
No, you can't just "enable" stage3d and have it work.
Look into Starling framework, that might be the easiest way for you (unless you have text inputs, which will require a bit of a workaround). You'll still have to change a few things in the code, though; it won't be a simple plug and play.

- 4,144
- 7
- 25
- 43