Showing posts with label as2. Show all posts
Showing posts with label as2. Show all posts

January 11, 2011

Actionscript:   / HTML text issue from an old Flash 8 project

I built a project back in 2006 that's amazingly still alive and making lots of money for a client. I had a bit of code that would insert an   into a textfield for dummy spacing in between other letters. Out of nowhere, this stopped working for the client, and all the text was space-less. This is what I had:
StringUtil.searchReplace( myStr, _dummyChar, '<span class="textDummy">&nbsp;</span>' );
This now fails to insert a space. I tried just using an actual space, but since this is an html textfield, multiple consecutive spaces don't keep making more room. So, I added a space after the &nbsp;, and magically, it works like it had in previous years:
StringUtil.searchReplace( myStr, _dummyChar, '<span class="textDummy">&nbsp;</span> ' );
Whew fun!

January 16, 2009

ActionScript: Random number function

I saw that one of the top results for "actionscript random number" in a Google search is incorrect, so I figured it would be a good idea to post another proper one.

Here's the ActionScript 3 version:
function randNum( low:int, high:int ):int
{
return Math.round( Math.random() * (high - low) ) + low;
}

And here's the ActionScript 2 version:
function randNum( low:Number, high:Number ):Number
{
return Math.round( Math.random() * (high - low) ) + low;
}