Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi.
In AS3 or HTML5 Canvas?
Regards,
JC
Copy link to clipboard
Copied
In AS3
Copy link to clipboard
Copied
If it is ActionScript, you can type cast the string to be a number. This for example:
trace("123"+4);
will give you "1234". But this:
trace(Number("123")+4);
will give you 127.
For HTML5 Canvas you can use JavaScript functions to get the same results. So,:
alert("123"+4);
will show "1234", but:
alert(parseInt("123")+4);
will show 127.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi.
Flash Player and AIR:
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
var loader:URLLoader = new URLLoader(new URLRequest("sample.txt"));
function completeHandler(e:Event):void
{
var loader:URLLoader = e.target as URLLoader;
var integer:int = int(loader.data);
trace(integer);
}
loader.addEventListener(Event.COMPLETE, completeHandler);
AIR only:
import flash.events.Event;
import flash.filesystem.File;
import flash.utils.ByteArray;
// the text file is in the documents directory
var file:File = File.documentsDirectory.resolvePath("sample.txt");
function completeHandler(event:Event):void
{
var bytes:ByteArray = file.data;
var str:String = bytes.readUTFBytes(bytes.length);
var strToInteger:int = int(str);
trace(strToInteger);
}
file.addEventListener(Event.COMPLETE, completeHandler);
file.load();
I hope it helps.
Regards,
JC
Copy link to clipboard
Copied
I tried it, it didn't work, but luckily I figured out how to do it. It was the parseInt function.
I had to make a Number var and then parseInt and it worked.
Thank you.