Iterate Shape children - Flash/as3 - actionscript-3

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"].

Related

Bring movieclips that have been added through editor to front

I have a game in which I have three different scenes. In the first scene, the objects (movieclips) were added through the flash editor, meaning that no actionscript was used to add them (not added with addChild). After that ive decided that I want to do the second and third scene entirely through actionscript and every object that is added is added with addChild(). The problem with this is that now the objects that have been added through actionscript appear in front of the ones added manually through the editor and I want it to be the other way around. I know that addChildAt() exists but I have over a 100 objects so it doesn't seem like a good option. In short: How do I set the Z-Indexes of movieclips that have been added through the flash editor and not through actionscript.
At first I tell you, this is not a good practice.
I give you some methods:
1.add child at to the back of others:
addChildAt(myDisplayObject,0);
so your added children will go back.
2.set the index of display obects:
first you should give them instance names, then in code:
setChildIndex(myDisplayObect,myIndex);
so you set the index of your display object.
I  H☺ P E  this helps

Find points in a MotionPath between frames (AS3)

I need to find the position of not-keyframe points in a motion path drawn on the stage.
What I can do is to find the position of the mc that is following the object at every frame (red dots) but I don't know how to access the MotionPath data to try to calculate intermediate positions.
One of the option is to create your motion path Pro grammatically check this example
Create a Motion Guide Programmatically
Another option if you want to continue working with path tool in flash , is to work on timebased instead of framebased

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.

AS3 - Using same symbol different image?

Basically I'm working on a new game and have decided to come up with the idea of having different enemies - however would I have to create multiple symbol's for these enemies or can I use that one symbol and change the image that is loaded onto it?
If yes - how would I go about doing this?
Currently the symbol is known as Enemy
Your symbol must be movie clip. In each frame there are different images and added by label. to change the enemy you can call:
Enemy.gotoAndStop(labels)// use Enemy.gotoAndPlay(labels) if you want the animated ones.
with labels is a string.

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

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/