as3 addChild into scaled movie clip & keep same scale and position - actionscript-3

ATTEMPTING:
Loading a movie clip (NoScale_mc) into a scaled movie clip (Scaled_mc).
ISSUE:
When I load the movie clip NoScale_mc into Scaled_mc it obviously scales too.
QUESTION:
How can I keep the NoScale_mc in THE EXACT SAME POSITION and THE EXACT SAME SCALE but yet still load it into the Scaled_mc using the addChild() method?

You could do a little reverse tirckery with math to try to accomplish this. So get the scaled values of the parent DisplayObject and use those values to inverse-scale the child DisplayObject.
For instance, the parent DisplayObject is scaled to: scaleX = 1.45 and scaleY = 4.6. So you can set the child DisplayObject to: scaleX = 1/1.45 and scaleY = 1/4.6.
This may produce odd results though, and will most-likely end up being a headache to maintain. You're probably better off adding the child DisplayObject to the stage on top of the parent, like Marty Wallace said. If you want to keep it looking aligned with the parent DisplayObject, then just set both of their x and y positions to the same thing (or with an offset, if that is what is desired).

Related

How to detect if there is a drawing/graphic drawn on a movie clip in AS3?

I am a newbie to AS3. I have a movie clip.I want to know if there is a drawing/graphic drawn over movie clip at all?
Simple, check the width and height of the MovieClip. Assuming you mean the MovieClip itself contains the drawing/graphic.
After seeing Fygo's comment
I did some testing and found out that the scale properties of the MovieClip will change depending on whether or not it has any graphics.
Meaning if you set the width and height to zero, the corresponding scaleX and scaleY will also be set to zero. So what you can do is check the scale AND the dimensions of the MovieClip. If both scales are 1:1 and both dimensions are 0:0, that means you didn't mess with the dimensions and it truly is graphic-less.
trace (awd.scaleX, awd.scaleY, awd.width, awd.height);
//If you get 1 1 0 0 as the output, the MovieClip is empty
Use readGraphicsData(). I assume that if it's empty it means there is nothing drawn there :)
It's not perfect though, read the reference
Maybe you just mean collision detection? To detect if two movieClips are touching...?
For that you need either:
HitTestObject - (checks if two objects touching by their box boundaries) - Link:
or HitTestPoint - (read description carefully) - Link:
A good tutorial explaining both methods is here: - Link:
example code:
if ( MC_one.hitTestObject(MC_two) )
{
trace("MovieClip One is touching/over MovieClip Two");
//add code needed to happen when touching/over. example below
//MC_two.gotoAndStop(2); //example tells touched MC_two to change frame to 2
}

AS3 - Setting BitmapData Dimensions

I'm brand new to AS3, trying to take a bitmap from the library and display it in the timeline with actionscript. Here's the code I'm using so far as per Adobe's site:
addChild(new Bitmap(new myBitmap(100, 100)));
and this works, but changing the dimensions in those brackets doesn't. How can I change the dimensions?
Also, how can I change the position of the bitmap? Right now it's at 0,0.
You first get a handler of that bitmap:
var theBitmap:Bitmap=new myBitmap();
Then, you can change its coordinates:
theBitmap.x=100;
theBitmap.y=100;
addChild(theBitmap);
In order to do scaling, you can also alter its scaleX and scaleY properties as with any other displayed object. In order to make a Bitmap object to be of certain size on screen, you have to scale it so that scaling parameter equals (new dimensions)/(old dimensions). But, if you want something else, you have to explain it further.

Getting graphic/movie clip x,y position from within another movieclip?

This should be fairly simple I'd think, I'm just not that familiar with actionscript haha.
I have a game where I have the background moving behind a character that stays in one position on screen. I'm relatively new to actionscript 3 but I'm wanting to have text boxes pop up whenever the player presses a key over certain objects passing in the background.
So, basically the background itself is a movie clip, and I have other graphics and movie clips within the background mc.
I was thinking of getting the player.x and y position and then "comparing" that position (>= and <=, etc.) with the graphic/movie clip in the background. But I just don't know how to obtain the x and y coordinate of the graphics/movie clips in the background mc.
You could try to target your movie clips in the background by getting their coordinates, then removing their parent's position (the background container).
Something like :
var finalXPosition:int = targetMovieClip.x - backgroundContainer.x;
var finalYPosition:int = targetMovieClip.y - backgroundContainer.y;
By substracting the target movieclip parent's position to its position, you gain the final position in the parent's scope coordinates.
It should work for you as soon as your character and your background container are situated at the same level of the display list.
Here is a quick diagram of what I try to explain (please forgive my inaptitude to draw nice and explicit drawings ^^)
Usually, when I stumble upon such a case, I try to make a quick and even dirty drawing, starting with what I want, then breaking down every useful data I have to achieve that result, you should keep that method in mind and try it the next time ! :-)

Dynamically adding tween to n MC's

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})
}

MovieClip resizes, but its children's height and width are not changed?

Changing the width and height of the parent MovieClip does not bring change in the width and height of the inner MovieClip. The parent MovieClip is placed at Stage and is resized manually. When I assign the dimension of the parent MovieClip to the inner MovieClip through code, the parent MovieClip dimension is changed. I want both MovieClip to be of same width and height at runtime. However, parent MovieClip dimension is changed at design time by me.
Example:
There are two MovieClip, one inside another. Now parent MovieClip is placed at Stage at design time and its dimension is (50,50) and the child MovieClip which is inside the parent MovieClip has also same dimensions (50,50). Now, I manually change the parent MovieClip dimension by pressing Q and stretching it with mouse, the dimension of the parent MovieClip is now (100,150) or whatever I like. Now double-click on parent MovieClip and check that inner MovieClip dimension remains same i.e. (50,50)
Now in AS3 code, I change the width and height of inner MovieClip like this:
saveheight = parentmc.height;
savewidth = parentmc.width;
now I change the child MovieClip according to the dimensions of the parent MovieClip like this:
parentmc.inner_mc.width = parentmc.width;
parentmc.inner_mc.height = parentmc.height;
but this brings change in parentmc also so I reassign value to parentmc like this:
parentmc.height = saveheight;
parentmc.width = savewidth;
In above case, parentmc and inne_rmc dimension should be same i.e (100 ,150). With swapping the values as above, I get parentmc and inner_mc to be of same dimension, but object size is never (100, 150), I have checked it with pixel-perfect air app.
In your code, you are neglecting to account for the transformation to the parent that you did with the 'Q' tool in the authoring environment. The childmc's width and height are expressed in terms of parentmc's transformed coordinate space. If you wish to scale the inner clip to a specific size in stage coordinate space you need to account for the scale of the parent that resulted from your transform:
parentmc.inner_mc.width = parentmc.width/parentmc.scaleX;
parentmc.inner_mc.height= parentmc.height/parentmc.scaleY;
Also, if the clips aren't aligned (e.g. registered by their upper left corner and with the child at 0,0), enlarging the child could push out the boundaries of the parent.
You can also use the parent's transform matrix if you prefer that over using scaleX and scaleY.
UPDATE 4.8.11: Were you perhaps asking to do this (runtime removal of the authoring-time transform)?
saveheight = parentmc.height;
savewidth = parentmc.width;
parentmc.scaleX = 1.0; // Undo authoring-time scale transform
parentmc.scaleY = 1.0; // Undo authoring-time scale transform
parentmc.inner_mc.width = savewidth;
parentmc.inner_mc.height = saveheight;
parentmc.width = savewidth;
parentmc.height = saveheight;
Note: I'm not at a computer set up with Flash to test this, so please leave me a comment if this does not do what you are expecting, and I will happily check my work and follow up.
it doesn't quite work like that,
you need to multiply the children by the scale of the parent.
the other thing you can do is use getBounds and then you can get the bounding rectangle of any child (and child's children etc) relative to the parent
I honestly don't understand what you're asking, because what you describe should work!
If we have a parentMC and a childMC both with a 50 height and 50 width, if you change the parentMC.scaleX = 2; it will apear to be 100 in width. The same goes for the childMC.
Could you please provide an example of what you're trying to do here? - or some code.