How to add symbols in layers? - actionscript-3

I am looking to know how to add an object inside a Layer, as you can see here :
I can't find a way to actually add my Movieclip inside the layer from the code side.

Short answer, no. Long answer, I don't think you can, layers are more like grouped display order. I've been using Flash for years and have never met this need or issue. You add the mc from the code at runtime, a moment where you don't really care which layer it goes into.
However, if your question is actually, how to add a mc at a specific index, then you can either addChildAt( mc, theIndexYouWant) or, simulate the layers by creating movieclips and inserting what you need inside of it.
In this case, you would have, on the stage, in a single layer, the movieclips: floor, toto, layer2 and layer3. You would then add, using the code, the mc you want in the toto movieclip.
If something is unclear, ask away :)

Related

Customize or create Starling animations, movements and Transitions

Since I don't know english very well, I'm not able to find clear examples and/or tutorials for what I'm trying to do.
So the (maybe stupid) question is:
How can I strongly customize tweens using Starling framework and make my Sprites(or MovieClips) following a line, curve or create every other non-linear movement that doesn't exist in Transition Class?
I have no problem with Basic Starling animation. So it should be a good start point.
Thanks in advance for examples, resources or suggestions.
PS. I already visit the "Starling Wiki" page about custom Transitions but, as a Beginner(almost Intermediate) coder I wasn't able to completely understand it.
I know there are many online resources about AS3/Starling/Flash/Nape/Box2D but it's not easy for a non-english Beginner programmer to understand them.
You can simple move Starling's movieClip by set .x .y .rotation
Since now, I haven't heard of scripted transition to make predefined non linear movement. As you said, you can move object from one position to another, but it won't happen in a curved line.
What I've done in the past is to predefine the path of the movement, as I needed exactly the same weird path. I did a path tween in Flash, then used one simple function to loop through all frames (using gotoAndStop()) and getting x and y property of the object, storing them in an array. This was done when initializing. Later on I could start animation on all my weird paths whenever I wanted, using onUpdate method of tween, and passing positions from the array I've populated in the beginning.
This of course is good if you have very weird paths. If you want very little curves, you could try to do a mathematical equation. Tween classes have an update function, which will be called on each frame. So on each frame you could do some calculations and modify the parameters. For example if you tween x and y properties, you could use the update function to add a random number to those values. Of course this will make very uncontrolled movement, I'm just giving an example.
The best solution I could think of, speaking of complexity/result ratio - to use Greensock's TweenMax (look at the second example) - it has a built in bezier tweening. This means it could move from point A to point B within a bezier curve. I think this will be a good solution for your problem :)

Flash, Drag and select multiple characters in game

I am learning to make games in Flash. I know I should probably use HTML5 or other platforms but let it be like this. I will learn those stuff later..
My question is like this, I want to select multiple characters in game. For example, I have 5 tanks. I want to drag-select them and move them to a point. How can I do that? Any mouseEvent or function for that? Moving them to a point is a different criteria I guess, but selecting a group of tanks. That's what I want to learn.
I am going to use Flixel game engine for this.
PSST! ~ If you guys don't want to help me, step by step by giving me exact code. I am fine! Just guide me in the right path and I will learn it myself.
First of all, do you know how to select one tank and move it where player clicked?
I'm not sure Is it an easy task for you. I'll give you some ideas about selection and how to detect it.
Bounds and Rectangles. Every tank has bounds represented as Rectangle, and by dragging your selection over tanks, you are forming also Rectangle. So you could check intersection of these rectangles
If you don't want to work with bounds, but with ready to use display object methods. By dragging Rectangle selection, you could form transparent shape, and check if it intersects with tanks This approach is slower than first.

Moving character on a specific stage Actionscript 3

I'm making a game with ActionScript 3.0. There's is one thing I can't figure out:
I have a big circle on the background. On this circle I want to let a character randomly move. But this character can only move on this circle, so it can't go to the background. Where do I need to start with this, how can i specify a specific stage like this?
P.S. I can't upload a picture yet, I've not enough "reputation points", otherwise I would have uploaded some pictures to get my question more clearly.
A general idea around which you can evolve is using hitTestPoint() method on your stage using current player's coordinates as the point being tested, and if this method returns false, this means the player has left the stage, and you need to put him back. Using previous location is the failsafe method, but you might also invent some other more smart way to do this.
The manual on hitTestPoint()

AS3 for moving a movieclip along a path

I am looking for a simple AS3 script to move/follow a movieclip (arrrow) along a manually drawn path in flash. Like.. it moves for the start point if the line to the end point of the line, also should rotate at curves automatically.
Also is it possible to duplicate this movieclip (arrrow) tho specific distance, like a ground of arrows moving along a path continuously with specific distance from eachother?
I am working on few infoGraphs and need this arrows animation to show the workflow.
I desperately needs this, pls help!
Cheers,
bp
There could be libraries that help with this, as George Profenza mentions in his comment, and it is certainly possible to calculate points along a bezier.
However, a much simpler solution is to do what people have done since Flash 4. Draw the curve in Flash, then create a motion tween along the curve using an empty MovieClip. At runtime, you can use addChild() to insert your MovieClip as a child of the empty one. You will have a lot more manual control this way, compared to the bezier library.

Actionscript 3 I need someon to help me with Collision Detecting(hiTestObject)

I will try to explain the issue as good as possible.
What I want to do is to check for collision between to objects. Also the bullet and the enemy, if it was 1 of the bullet and 1 of the enemy it would be no problem, but after one day on google and tryed like every solutions I can't get it to work, or I find a solution that's absolutely terrible explained.
Im going to make it easyer. I have MainClass.as that document class.
It's one class for the Enemy and one for the Bullet. As I hope everyone understand I wan't to check if the bullet hit's the Enemy. Or the other way. Since the bullet's are been made while clicking for example it is not possible to direct refere to the bullet. What I have tryed is using sprite container, it does work if i place the bullet on the enemy just to check, but if I place one under and on over that's NOT hit the Enemy it's still says that the enemy got hit.
Note, the Enemy are dragged on stage, since im going to have multiple of them. I could also add them with code. Ive tryed to use Array to shuffle between all the enemys but I can't get it to work.
I know this was much text. Hope someon are willing to help me out, it is so frustrating...
Best regards HFherasen!:):)
Well, if you don't use a physics engine, like Box2DFlash, it can be frustrating.
First, you have to know the speed/frame of the bullet, because if it goes beyond the target in one frame, simple detection won't work.
Than, you should have a velocity and direction of the bullet.. For simplicity, lets use one point of it. (the head of the bullet, or the middle)
The bullet usually moves a lot faster than the targets, so you can assume the targets fixed.
The target is a rectangle, or polygon possibly rotated.
Now you have a target, and a line for the bullet (from the point and direction).
http://keith-hair.net/blog/2008/08/04/find-intersection-point-of-two-lines-in-as3/
You can use this (converted to as3), with all sides of the target (or only the ones facing to a bullet), and if one matches, the shot will hit a target.
If your bullet is slower, you can have the position change of the frames as your first line. Than you'll know, when it hits a target. This is pretty fast, and works well. Hope it helped.