Flash AS2 - duplicating text balloons MC scale (SOLVED)

A place for tutorials on how to get the most out of Flash

Flash AS2 - duplicating text balloons MC scale (SOLVED)

Postby Ivan-Aedler » Sun Apr 27, 2014 3:49 pm

Hello,
Its me again, breathing between game development.

I am into a dilemma: I need to use foreground text balloons, but reusing the default ones (which is 'background balloons'), already inside each enemy scene.
For example: _root.Level.goomba.scene1.balloon1, _root.Level.goomba.scene2.balloon2........

But I need it to be in the foreground layer (Level.HUD).
_root.Level.HUD.balloon1, _root.Level.HUD.balloon2....

I am almost there. Let's call _root.Level.goomba.scene1.balloon1 as _obj (as I code inside a function). Tb3m is the balloon1, in the library (identifier).
Code: Select All Code
_root.Level.HUD.attachMovie("Tb3m", "Tb3m", 10000+_root.balloonAuxAux); //it puts balloon1 (Tb3m) as '_root.Level.HUD.Tb3m'.

//copying properties from the old balloon
_root.Level.HUD.Tb3m._width=_obj._width;
_root.Level.HUD.Tb3m._height=_obj._height;
_root.Level.HUD.Tb3m._xscale=_obj._xscale;
_root.Level.HUD.Tb3m._yscale=_obj._yscale;
_root.Level.HUD.Tb3m._rotation=_obj._rotation;

//Change coordinates, in order for both balloons be in the same coordinate plane.
_obj.point = new flash.geom.Point(0,0);
_obj.localToGlobal(_obj.point);
_root.Level.HUD.globalToLocal (_obj.point);

_root.Level.HUD.Tb3m._x=_obj.x;
_root.Level.HUD.Tb3m._y=_obj.y;



But the balloon is not scaling. I get the current xscale and yscale, but it remains huge. In the picture below, you can notice the older balloon (the tail of it) because I havent removed it just for comparison.

balloon foreground error.jpg
balloon foreground error.jpg (24.31 KiB) Viewed 2109 times

I just want to know how to capture that scaling.
I tried duplicateMovieClip() but it only works by duplicating objects to the same timeline hierarchy. I need different hierarchies.
Just to mention that _root.Level.goomba has the default scale, but _root.Level.goomba.scene1 has a custom scale (I did it manually, shrinking it). The same with _root.Level.goomba.scene1.balloon1 and _root.Level.goomba.scene2.balloon2 (because the default scale for scene1 and balloon are huge).

I need to retain the current balloon1 and balloon2 relative scale, so I can duplicate it with the same position.
Thank you for any help!
Last edited by Ivan-Aedler on Thu May 01, 2014 4:39 am, edited 1 time in total.
User avatar
Ivan-Aedler
 
Joined: Fri Jun 03, 2011 6:34 am
Location: GMT -3

Re: Flash AS2 - duplicating text balloons MC and retain scal

Postby Anonymouse » Sun Apr 27, 2014 10:37 pm

_root.Level.HUD.Tb3m._xscale = _obj._xscale * _obj._parent._xscale / _root.Level.HUD._xscale;

Perhaps? The product of obj.xscale and obj.parent.xscale will give obj's scale relative to _root.Level. We then divide by the HUD xscale (ignore if 1) to account for that.
User avatar
Anonymouse
 
Joined: Sun Nov 24, 2013 2:47 am

Re: Flash AS2 - duplicating text balloons MC and retain scal

Postby Ivan-Aedler » Mon Apr 28, 2014 3:17 am

Anonymouse Wrote:_root.Level.HUD.Tb3m._xscale = _obj._xscale * _obj._parent._xscale / _root.Level.HUD._xscale;

Thank you!!! Thats it! Now I just need to get the correct coordinates. I am coding it right now. ;)

Code: Select All Code
_root.Level.HUD.Tb3m._xscale = _obj._xscale * _obj._parent._xscale / _root.Level.HUD._xscale;
_root.Level.HUD.Tb3m._yscale = _obj._yscale * _obj._parent._yscale / _root.Level.HUD._yscale;
User avatar
Ivan-Aedler
 
Joined: Fri Jun 03, 2011 6:34 am
Location: GMT -3

Re: Flash AS2 - duplicating text balloons MC and retain scal

Postby Ivan-Aedler » Tue Apr 29, 2014 12:01 am

Well, it worked with a two _xscale hierarchies (_parent._parent), but how about three or more?
I have a situation where there are three '_parent's.
So I tried:

Code: Select All Code
_root.Level.HUD.Tb3m._xscale = _obj._xscale * _obj._parent._xscale * _obj._parent._parent._xscale / _root.Level.HUD._xscale;
_root.Level.HUD.Tb3m._yscale = _obj._yscale * _obj._parent._yscale * _obj._parent._parent._yscale / _root.Level.HUD._yscale;


And it didnt work :(
User avatar
Ivan-Aedler
 
Joined: Fri Jun 03, 2011 6:34 am
Location: GMT -3

Re: Flash AS2 - duplicating text balloons MC and retain scal

Postby Ivan-Aedler » Wed Apr 30, 2014 4:15 am

Just saying it didnt work after all.
I was seeing the older balloons :(

Every other case regarding three or more hierarchies break the balloon size.

error parent scale  parent parent scale.jpg
error parent scale parent parent scale.jpg (104.32 KiB) Viewed 2000 times

I need this kind of code because I have different scaled MCs.
Code: Select All Code
if (_obj._parent._parent._name=="Level")  {
 _root.Level.HUD.Tb3m._xscale = _obj._xscale * _obj._parent._xscale / _root.Level.foreground._xscale;
 _root.Level.HUD.Tb3m._yscale = _obj._yscale * _obj._parent._yscale / _root.Level.foreground._yscale;

} else if (_obj._parent._parent._parent._name=="Level") { //enemies optimized (no scene main) and scenes like daisy
 _root.Level.HUD.Tb3m._xscale = _obj._xscale * _obj._parent._xscale * _obj._parent._parent._xscale / _root.Level.foreground._xscale;
 _root.Level.HUD.Tb3m._yscale = _obj._yscale * _obj._parent._yscale  * _obj._parent._parent._yscale / _root.Level.foreground._yscale;

} else if (_obj._parent._parent._parent._parent._name=="Level") { //enemies
 _root.Level.HUD.Tb3m._xscale = _obj._xscale * _obj._parent._xscale * _obj._parent._parent._xscale * _obj._parent._parent._parent._xscale / _root.Level.foreground._xscale;
 _root.Level.HUD.Tb3m._yscale = _obj._yscale * _obj._parent._yscale * _obj._parent._parent._yscale * _obj._parent._parent._parent._yscale / _root.Level.foreground._yscale;

} else {
 _root.Level.HUD.Tb3m._xscale = _obj._xscale * _obj._parent._xscale / _root.Level.foreground._xscale;
 _root.Level.HUD.Tb3m._yscale = _obj._yscale * _obj._parent._yscale / _root.Level.foreground._yscale;
}


What I really need is: take a given object (MC) already in the stage, with a current RELATIVE scale, then duplicate it to another hierarchy, that is, in another object, be it in PARENT mc, PARENT of PARENT, or outside, while RETAINING the same scale.


And before one can say 'google is your friend', just check this:
I'll keep searching and trying other code.

scale question is rare.jpg
scale question is rare.jpg (129.76 KiB) Viewed 2000 times
User avatar
Ivan-Aedler
 
Joined: Fri Jun 03, 2011 6:34 am
Location: GMT -3

Re: Flash AS2 - duplicating text balloons MC and retain scal

Postby Anonymouse » Wed Apr 30, 2014 8:18 pm

I'm gonna write this in pseudo code, because AS2 is almost painful to write in, so you will have to adapt it a bit. I hope the general idea is clear: we find the true scale of a movieclip as the product of everything is the display tree above it, then divide that by the scale of everything above the target.

http://pastebin.com/fyddSwTW

Then you would call sclaeAtoB(Tb3m, baloon1);
User avatar
Anonymouse
 
Joined: Sun Nov 24, 2013 2:47 am

Re: Flash AS2 - duplicating text balloons MC and retain scal

Postby Ivan-Aedler » Wed Apr 30, 2014 10:13 pm

Anonymouse Wrote:I'm gonna write this in pseudo code, because AS2 is almost painful to write in, so you will have to adapt it a bit. I hope the general idea is clear: we find the true scale of a movieclip as the product of everything is the display tree above it, then divide that by the scale of everything above the target.

Thank you, I corrected it for AS2, I hope its correct. Flash compiled it without errors.

Code: Select All Code
function scaleAtoB(a ,b) {
   a._xscale = trueXScale(a)/trueXScale(b._parent);
   a._yscale = trueYScale(a)/trueYScale(b._parent);
}


function trueXScale(mc) {
     var xscale : Number;
     while(mc != _root)
     {
          xscale *= mc._xscale;
          mc = mc._parent;
     }
}

function trueYScale(mc) {
     var yscale : Number;
     while(mc != _root)
     {
          yscale *= mc._yscale;
          mc = mc._parent;
     }
}


_root.scaleAtoB(Tb3m, ballon1) had no effect (because I run this code in the source balloon).
_root.scaleAtoB(_root.Level.HUD.Tb3m, ballon1) , or in this case, _root.scaleAtoB(_root.Level.HUD.Tb3m, _obj) because I run it in the source as mentioned, which will spawn the new one, worked with _parent._parent situation (this _obj being _root.Level.HUD.Tb3m) - apparently - but it didnt work for deeper levels (+1 level): _root.Level.morton.scene1.balloon1 and +2 level: _root.Level.goomba.goomba_main.scene1.balloon1

I also tried as '_root.scaleAtoB(_obj,_root.HUD.foreground.Tb3m)'.

I am testing with some variances.
I detected, for example, that xscale and yscale (inside the functions, without the _ ) is lacking a definition, like xscale=1. Multiplying them without definition will be like UNDEFINED *=mc._xscale.
Even if 'Number' gets resetted to 0, 0*=something <=> 0

The error goes on.

error parent scale  parent parent scale2.jpg
error parent scale parent parent scale2.jpg (29.97 KiB) Viewed 1971 times

error parent scale  parent parent scale3.jpg
User avatar
Ivan-Aedler
 
Joined: Fri Jun 03, 2011 6:34 am
Location: GMT -3

Re: Flash AS2 - duplicating text balloons MC and retain scal

Postby Anonymouse » Thu May 01, 2014 1:01 am

Code: Select All Code
function scaleAtoB(a ,b) {
   a._xscale = 100*trueXScale(b)/trueXScale(a._parent);
   a._yscale = 100*trueYScale(b)/trueYScale(a._parent);
}


function trueXScale(mc : MovieClip) {
     var xscale : Number = 100;
     while(mc != _root)
     {
       trace(mc.name);
          xscale *= mc._xscale/100;
          mc = mc._parent;
     }
    return xscale;
}

function trueYScale(mc) {
     var yscale : Number = 100;
     while(mc != _root)
     {
          yscale *= mc._yscale/100;
          mc = mc._parent;
     }
    return yscale;
}


Tested and working. My original code had a few flaws (not setting scale, functions not returning a value) but also there was a problem in the conversion to AS2, in which scales are done as percentages, so need to be multiplied by 100.
User avatar
Anonymouse
 
Joined: Sun Nov 24, 2013 2:47 am

Re: Flash AS2 - duplicating text balloons MC and retain scal

Postby Ivan-Aedler » Thu May 01, 2014 3:21 am

Anonymouse Wrote:Tested and working. My original code had a few flaws (not setting scale, functions not returning a value) but also there was a problem in the conversion to AS2, in which scales are done as percentages, so need to be multiplied by 100.

Thank you! It worked!! Image Image
Yes, the 'return' statements, I also forgot to add them in the pseudocode.

I will share this information in Kirupa, thank you dozens of times!

Image
User avatar
Ivan-Aedler
 
Joined: Fri Jun 03, 2011 6:34 am
Location: GMT -3


Return to Tutorials



Who is online

Users browsing this forum: No registered users