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
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);
}
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"
Copy link to clipboard
Copied
you need to write an eval function.
Copy link to clipboard
Copied
Thank you very much
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thank you sir
I learned a lot
Copy link to clipboard
Copied
you're welcome.
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
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?
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.