PDA

View Full Version : as2 toString



doc
01-26-2010, 02:39 PM
Ok, i havent posted one of these for a long time, but there's something i just cant figure out, which is this toString. I understand that it takes a value and transforms it into a string, and thats all good. But earlier i was trying to figure out how to change the RGB color of a mc (which i can now do) and i came across this example: http://www.flashvault.net/tutorial.asp?ID=115
If you look at the code on the second page (this is it):

onClipEvent(enterFrame){
_parent.redRGB = (_parent.RedSlider.RedControlBar._y+122).toString( 16);
if (length(_parent.redRGB) == 1)
_parent.redRGB = "0" + _parent.redRGB;
_parent.greenRGB = (_parent.GreenSlider.GreenControlBar._y+122).toStr ing(16);
if (length(_parent.greenRGB) == 1)
_parent.greenRGB = "0" + _parent.greenRGB;
_parent.blueRGB = (_parent.BlueSlider.BlueControlBar._y+122).toStrin g(16);
if (length(_parent.blueRGB) == 1)
_parent.blueRGB = "0" + _parent.blueRGB;
finalColor = "0x" + _parent.redRGB + _parent.greenRGB + _parent.blueRGB;
_parent.circleColor.setRGB(finalColor);
_parent.circleColor.setRGB(finalColor);
}

It uses the toString in a weird way, and im not sure how it works. It does (number).toString(another number), and it seems to work. When I try to replicate this, i get some weird results (after tracing).
50.toString(16)------Error
50.5.toString(16)-------32
50.5.toString(43)--------50.5
220.5.toString(16)--------dc

now i know that for the last one, dc is the rgb code for 220.5. But im really confused about all of the other ones. Does anyone else understand this?

Edit: ok so i figured out that the number in parentheses is a base conversion, so it will return the number before the period in the base given. But i still cant figure out why whole integers dont work :/