How to copy Movieclip display properties as a vector into another movieclip - actionscript-3

For my project I need to copy the graphics of a Movieclip with all of its children without copying anything else into a second Movieclip. I cannot use the Bitmap classes because I need the graphics to be displayed as a vector and I cannot use a method that simply copies the clip by calling the instructor ie:
var copy:MovieClip = clip.constructor
Is there any way to copy only the display portions of a clip into another Movieclip without turning it into a bitmap?
Thanks

Cloning display objects out of the box in as3 is no easy task. Here is a tutorial explaining the several approaches that have been attempted over the years and what works and what does not:
http://www.dannyburbol.com/2009/01/movieclip-clone-flash-as3/

Related

Iterate Shape children - Flash/as3

I am using Flash CC.
I have drawn 7 rectangles using the Rectangle Tool.
I then converted the 7 as one movie clip (By hitting F8).
The Problem:
I want to be able to iterate through these shapes and move each individually.
However the 7 rectangles seem to be encapsulated into the ONE shape and I can't access them.?
If I use .numChildren on the movie clip, it returns 1.
If I use .getChildAt("anything > 0") its a null reference exception.
Please help,
I don't understand how this is so difficult.
I have searched for ages to find the solution to this and for the life of me I can't.
Thanks in advance.
(P.s) Instantiating the rectangles in code works, but I need to be able to do this via Flash CC as I will be importing artist material for manipulation.
Your best choice is to make every shape in your made movie clip a movie clip as well.
In Flash go into your made MovieClip (I will call it containerMC for easier understanding) and make every shape a MovieClip by hitting F8. You can also give them instance names, if you want, just make sure they're unique.
Then your containerMC will return numChildren value 7 in your case.
You can move/access your shapes in the containerMC via getChildAt(), or by using their instance names that you've provided via containerMC.instance1 or containerMC["instance1"].

Instantiate MovieClip with its layers?

I have searched a lot lately, I found that I can load an external swf file to my haxe project at compile time, and use the movieClips via their IDs as Classes types ..
That's cool& nice, but how it would work when I instantiate a MovieClip that has layers?
What I have is MovieClips with layers, layer of image, and a layer of text over the image layer.
So, is this achievable? will I be seeing instances of movieClips (images& texts over them) ?
Let's first dissect the flash terms in terms of code,
Layers :
Consider the layers as grouped z indexes. A single layer with multiple objects will also assign sub z indexes to each clip (see the send to back option in context menu)
The flash IDE provides you a nice interface to group & lock a few instances of objects, while working on the other. Each such group is a layer.
At runtime, every layer (with it's objects) will be concatenated into one single list (the display list) and the objects placed onto the stage in order of their position in the list.
Frames :
Frames are slices of time controlled by the fps property of the flash player. So if you have 12 fps, it means that whatever code you put in that frame of time will receive attention for 1/12th of a second.
Of course there is code being written for anything you do inside a frame or layer. The code, for example that you put in manually in IDE is added in by calling the addframescript internally.
MovieClip
The MovieClip class itself is actually an IDE related thing. The split being Sprite Class plus a timeline (collection of frames) plus associated properties & methods.
The Movieclip class thus provides you with properties like currentFrame, totalFrames, etc & methods like gotoAndPlay(), stop(), etc to interact with the flash controlled class.
Considering all of the above together, you should expect to see different images/text/objects at different intervals of time as defined in the frames when you access the movieclip.
I haven't spent a lot of time in flash, but the answer to your question comes from having a better understanding of how Flash/AS3 works, and not so much to do with Haxe.
Quoting this answer:
Layers only exist in the Flash IDE. They are not part of Flash Player's display list system. So you can't specify what layer a child goes into. Use addChild() or addChildAt() to add children to containers.
So that means Haxe will not have any concept which object is in which layer, nor would AS3 for that matter. The correct approach seems to be to use containers with IDs, which are recognised by AS3 or Haxe, and then add children to the containers.
TLDR: use containers movie clips, not layers.

How do I approach rendering text in a fully sprite based game? (ActionScript 3)

I've created a Canvas class which has an Array of multiple instances of CanvasEntity. Each of these has a skin property which is a reference to a previously created instance of BitmapData, representing some graphics that can be used.
The Canvas runs through this list each frame to perform a render:
lock() the canvas
Clear the canvas using fillRect().
Loop through the aforementioned Array and use copyPixels() on each of the instances' skin properties.
unlock() the canvas.
This is all fine, but now I'm a bit unsure of the best way to approach rendering text in the same fashion.
Do I need to make a sprite sheet with all of my glyphs on it, just like I do for all the frames of any other object? Or is there a simpler way to create a piece of BitmapData that will represent these?
Making a sprite sheets seems painful as there would need to be individual objects representing each glyph to be rendered.
So far I have this as a sprite sheet:
You don't need an individual object for every character. If you want a low-cost text display, have a single class that extends CanvasEntity and accepts a string in the constructor, copies relevant data from the spritesheet to the skin.
The average game doesn't contain that many text. It's generally not a performance critical part that requires to much optimization. You could just create a normal sprite, add a TextField with the text and style you need and copy that graphic to canvas. Maybe chache the text graphics if you need them more often.
If you want some animation (character-by-character-appears-with-annoying-sound-of-typewriter-effect), you probably should go with the sprite sheet. But you can create that dynamically just once, using the same technique. Loop through every possible character of your font, draw it to your sheet.

Merging MovieClips into a larger MovieClip

I have these 2 separate FLA (AS3) files and I want to merge them together. One FLA, let's name "Animation.fla", consists of a 1-frame animation with a class assigned to its main stage, let's label it "MainStage.cs." The other FLA file, label it, "Navigator.fla", consists of 3 frames where I have to navigate different frames to get to the animation on the Animation.fla.
I have tried nesting the two but I gain errors when trying to convert the whole Animation.fla to movieclip and put it on the frame of the Navigator.fla. It's seems it's not the correct way to do it.
Please fill me in with ideas on merging animations with Classes since I'm still new to this.
I have tried nesting the two but I
gain errors when trying to convert the
whole Animation.fla to movieclip and
put it on the frame of the
Navigator.fla. It's seems it's not the
correct way to do it.
This is one way to do it. It could be that your code has errors. Please post your code.
In the meantime, check if:
-your MovieClips have instance names
-you are referencing your MovieClips correctly in your code.
You could you create a new movieclip on the stage of Animation.fla and select all of the frames in Navigator.fla, right click and "copy frames". Then go back to Animation.fla and paste them into your new movieclip. This will work if you don't have a main class in Animation.fla.

Is it possible to create a MovieClip using ActionScript 3 code or MXML?

I'm using the Flex 3 SDK and the free FlashDevelop IDE.
As I don't have FlexBuilder or Flash CS4 Professional I cannot make MovieClips graphically.
So instead I want to create a simple MovieClip using code or MXML. For example, lets say I want to create a MovieClip with 3 frames, and load a bitmap into each frame to create a simple animation.
Is this possible? I've had a good google around and the only examples I can find are of loading existing MovieClips and adding them to a stage.
You can create a movieclip with this simple code:
var mc:MovieClip = new MovieClip();
stage.addChild(mc);
That is of cause just and empty movieclip, you can draw on it with graphics property (see here).
As far as I know there is no way to create frame with actionscript. Though there might be some undocumented methods. There are some functions that do not appear in the documentation (like the addFrameScript method).
I would say the best way (if you absolutly can not use the Flash CS4), would be to have a series of Loader objects, and the hide and show them on every in sequence.
Just put them in an array and listen for the enterFrame event.
You can load in the bitmaps in the Loader objects.
If you use the links and checkout the examples in the documentation, I think you should be able to figure it out.
As far as I've seen, there is no easy way to create a MovieClip in Flex which behaves in a way one might see as comparable to Flash's implementation MovieClip. But I don't think you really want a MovieClip to begin with. Flex does not really play well with non-flex objects. Yes, it is possible to add something to a UIComponent, but you are much better off working withing the Flex framework than doing workarounds.
I would use the mx:Image tag to load your images. It is generally the cleanest way to load an image into Flex. It will let you embed the object into the SWF at compile time, which means that you will not have to point to an outside file. I will caution about having too many embedded graphics -- that will kill your download time and possibly your performance.
If you are only interested in having an animation move or re-size, then I would use the Move and Resize objects which are native Flex Tweens.
Your best option might be to extend the UIComponent class, add a MovieClip as a child-component, and apply the settings from MXML via proxy. e.g.,
public function set movieFrames(value:Array):void {
for each(var b:Bitmap in value) {
//add bitmap to _movieclip object.
}
}
You want a Sprite not a MovieClip. And use time instead of frames. There's a Timer class and a getTimer() function. Use them.
create a class that extends/implements Sprite.
Add a Loader class.
Google it exactly how it's done. (flashtuts.com or sth like that).