• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Convert text file to integers

New Here ,
May 06, 2022 May 06, 2022

Copy link to clipboard

Copied

I have a text file with numbers in it. So what I want to know is this.

How can i convert them into integers?

Views

496

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 07, 2022 May 07, 2022

Copy link to clipboard

Copied

Hi.

 

In AS3 or HTML5 Canvas?

 

Regards,

JC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 08, 2022 May 08, 2022

Copy link to clipboard

Copied

In AS3

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 07, 2022 May 07, 2022

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 19, 2023 Jan 19, 2023

Copy link to clipboard

Copied

How do I do the parseInt function with this textfile in Animate CC?

Or Actionscript3?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 20, 2023 Jan 20, 2023

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 26, 2024 Jan 26, 2024

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines