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

"Include" external .txt file in AS3

Explorer ,
Apr 28, 2023 Apr 28, 2023

Copy link to clipboard

Copied

I want to include external code without importing a custom class in AS3.
Is there a way to insert a .txt file in a remote directory into AS3.0 code?
Simple example code please.

Thank you

 

Views

767

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
Engaged ,
Apr 28, 2023 Apr 28, 2023

Copy link to clipboard

Copied

You can use the load() method of the flash.net.URLLoader class to load an external .as file at runtime and execute its contents via the eval() method.
For example:

// create a URLLoader instance
var loader:URLLoader = new URLLoader();

// specify the URL of the external .as file
var url:String = "http://example.com/examplefile.as";

// add an event listener for when the file has loaded
loader.addEventListener(Event.COMPLETE, onFileLoaded);

// load the file
loader.load(new URLRequest(url));

// this function will be called when the file has loaded
function onFileLoaded(event:Event):void {
  // get the loaded file's contents
  var loadedCode:String = event.target.data;

  // execute the loaded code using the global 'eval' function
  eval(loadedCode);
}

 

 

 

- Vlad: UX and graphic design, Flash user since 1998
Member of Flanimate Power Tools team - extensions for character animation

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
Explorer ,
Apr 28, 2023 Apr 28, 2023

Copy link to clipboard

Copied

Scene 1, Layer 'Music_List', Frame 1, Row 51, Column 3 1180: Called undefined method eval.


I get this error message
Please let me know if there is an alternative way or what to "import"

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 ,
Apr 28, 2023 Apr 28, 2023

Copy link to clipboard

Copied

you need to write an eval function.

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
Explorer ,
Apr 29, 2023 Apr 29, 2023

Copy link to clipboard

Copied

Thank you very much

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 ,
Apr 29, 2023 Apr 29, 2023

Copy link to clipboard

Copied

@Choi24652308akbg 

 

you can save a user modified list on your server (html5) or android/ios device (as3) and retrieve it and present it to the user when they re-log into their account, but you're not going to be running anything as3 from a file server. ie, browsers do not support as3/flash players.

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
Explorer ,
Apr 29, 2023 Apr 29, 2023

Copy link to clipboard

Copied

Thank you sir
I learned a lot

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 ,
Apr 29, 2023 Apr 29, 2023

Copy link to clipboard

Copied

LATEST

you're welcome.

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 ,
Apr 28, 2023 Apr 28, 2023

Copy link to clipboard

Copied

Hi.

 

Can you give an example of why do you need to load ActionScript code from a .txt?

 

As ActionScript is converted to bytecode in compile time, loading code externally doesn't make too much sense for me.

 

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
Explorer ,
Apr 28, 2023 Apr 28, 2023

Copy link to clipboard

Copied

For example, whenever I edit a music list uploaded to the server, can the user use the automatically modified list when the user runs the program?
Or can the user just use the list created at compile time?

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
Explorer ,
Apr 28, 2023 Apr 28, 2023

Copy link to clipboard

Copied

Trying it on my desktop now, I realize I was very mistaken.
Thank you very much for your great teaching.

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