Dynamically adding tween to n MC's - actionscript-3

Here's what I'm aiming for. I'm querying the Rotten Tomatoes API for Upcoming Movies. For each movie returned, I'm creating an instance of MovieIcon (MC). I'm then adding this MC as a child of a Container MovieClip that's already on the scene. Each time, I'm incrementing the xPosition of each MovieIcon MC such that, they're positioned next to each other.
My container MC has a mask applied to it, therefore any child objects that are positioned beyond the size of the mask, they're are hidden from view.
How can I dynamically add a tween/easing animation between all these MovieIcon MC's so that when I hover over the Container MC, it 'scrolls' left or right, depending on the mouse motion?
Thanks in advance.

First I would recommend using a tweening library.
TweenLite and Tweener are good options
http://www.greensock.com/tweenlite/
http://code.google.com/p/tweener/
Both of these include docs that will help you get everything set up in your project.
Then you should be able to add a ROLL_OVER event to each of your MovieIcon MC's
MovieIcon.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
Inside your handler you can use the event.target property to get a handle on the over MovieIcon.
Assuming your using TweenLite you can go and add your tween to that target
private function handleRollOver(e:MouseEvent):void{
TweenLite.to(e.target, duration, {x: new x value, any other prop: any other val})
}

Related

exception, information=ReferenceError: Error #1056: Cannot create property ground on Main. (FLASH As3)

I have a deep problem which I have encountered.
I am adding a movie clip inside to another movie clip and flash doesn't like this.
What I'm doing is dynamically adding a movieclip to a movieclip that hasn't been added dynamically.
movieclip 1
private var tim:player = new player();
//inside main
tim.addChild(ground);
now ground is an instance name that hasn't been added via code. It's on the stage in flash and it's a movievlip with the instance name ground.
What can I do to fix this please.
Basically I wasn't really understanding As3,
From reading As3 101 - Display Lists I was able to understand that all things like sprites, shapes and movieclips are added to a display list.
In order to have added tim to a parent, that parent would have to be present.
This means that the parent would need to be added to the display list.
addChild(container);
You can see that container is now part of the display list.
This means I can now:
container.addChild(character);
Add the character to the container, and this now becomes a display object container
I can now trace what's in the container.
trace(container.numChildren);
In this container there are 3 childrens, my ground, the player and the enemy :D

Disable mouse event for a specific child of a movieclip

I've a MovieClip that contains lot of children.
One of them is a big (and useless) shadow the graphic designer put there to make my life harder (and also the user's one, probably)
:)
Now I'm facing a little issue: the shadow is catching the MouseEvents attached to the main MovieClip (its parent), and this is very bad because it's very distant from the rest of the graphic. I'm now trying to avoid it.
Obviously I've already tried to set the shadow mc's properties mouseEnabled and mouseChildren to false, but it doesn't work.
I've found a previous thread (here), facing the same situation. But the solution accepted looks like it's not working for me.
What I am missing?
If mouseEnabled and mouseChildren is not working for you then use e.target.name property.
But first you will have to give a name to that shadow MovieClip (say shadowMC).
If you added it dynamically then use,
yourDynamicMC.name = "shadowMC"
If added manually on the stage then give instance name as "shadowMC",
Then, inside your code where you have MouseEvent function for parent MovieClip add the following lines
if(e.target.name != "shadowMC")
{
//Then proceed
}
Reading your question, I am assuming you already tried to set the parent MovieClip's mouseChildren to true with mouseEnabled to false and then set the children's mouseEnabled to true (except for the shadow). This solution should work in my opinion so I am guessing the event might be caught by one parent of your movieclip (you do not give much information about this).
Try to add a listener to the stage to see which object is receiving your MouseEvents:
import flash.utils.getQualifiedClassName;
stage.addEventListener(MouseEvent.CLICK, onClick);
private function onClick(event:MouseEvent):void
{
trace(event.target.name, getQualifiedClassName(event.target));
}
Try changing the hit area of your MovieClip. see the MovieClip doc here, this will override you MovieClip zone.

Moving a child MC to stage but remaining its animation

Is it possible to remain an on going animation on a child MC while moving the MC to the stage (same level as its parents)
If by using removeChild and addChild again the animation will not be consistancy.
You don't need to removeChild/addChild if you're just changing parents. Just calling addChild on a child that already has a parent, will re-parent the child automatically.
I haven't tested your exact problem. But if the MovieClip stops playing when you call addChild, you could just store the current frame and then resume playing from that frame after you've called addChild. Like this:
var frameNumber : int = myMovieClip.currentFrame;
newParent.addChild(myMovieClip);
myMovieClip.gotoAndPlay(frameNumber);

as3 dynamic index change for added objects on stage

I have added some backgrounds on stage and then on top of that adding another background and all these are movieclips.
At some time i have to remove the backgrounds and then it should be added but here problem am facing is the background become coming front.
so is there any function like send to back or bring to frond based on the movie clip names.
You want to experiment with :
setChildIndex(object, z-value)
This set the depth of the object on the stage.
swapChildren (object1, object2)
This exchange the position of two objects on the stage.
setChildIndex
swapChildren
swapChildrenAt
addChildAt
Use addChildAt(index);
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html#addChildAt()

Movieclip stacking in Actionscript

I'm building a game of which the interface is one of the first items to load on screen. Sound button, pause and all the bits -
During the game - all manor of things are dynamically added and removed to the stage. Therefore my interface goes behind my game scene.
How do I ensure the movieclip always stays on top?
Can I override the addChild of my Document Class and every time a new child is added, I restack the interface to the top?
You can use setChildIndex to rearrange objects that are already contained within a MovieClip or Sprite. For example, if you have an object called container, which contains a redBall, blueBall and many other ball objects, you can use the following to make sure redBall is behind everything else:
container.setChildIndex(redBall, 0);
Equally you can make sure that blueBall will be displayed infront of everything else using:
container.setChildIndex(blueBall, container.numChildren-1);
addChildAt will sort you out for adding children straight into their correct position, and setChildIndex will allow you to re-position objects already placed. Hope that helps.
debu
Look into addChildAt, it allows you to specify the index that the new object should be added too.
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html#addChildAt%28%29
A good strategy is to keep all interface elements in one parent Sprite/MovieClip, and all game assets in another. (With the interface one on top)
With your guys suggestion I made this, apparently, if you addChild an object already on the screen, it's simply reindex'd to the top. Does this look ok?
private var topLevelChildrenArray:Array = [];
public function addTopLevelChild(child:DisplayObject):DisplayObject
{
topLevelChildrenArray.push(child)
return this.addChildAt( child, this.numChildren - 1 );
}
override public function addChild(child:DisplayObject):DisplayObject
{
this.addChildAt(child, this.numChildren);
for each(var topChild:DisplayObject in topLevelChildrenArray)
{
super.addChild(topChild);
}
return child
}