Hi! So, I just started trying to transition from AS2 to AS3 last week, and as an initial exercise I’m trying to figure out how to load images/swfs from outside of my FLA.
I’ve come across the loader class, but I’m having some problems getting it to display the file that it loads…
Here is my code…
package {
import flash.display.*;
import flash.events.*
import flash.net.URLRequest;
public dynamic class ArtWork extends Sprite {
var path:String;
var work_title:String;
var work_medium:String;
var work_description:String;
public function ArtWork(con_path:String = "", con_title:String = "", con_medium:String ="", con_description:String="") {
path = con_path;
work_title = con_title;
work_medium = con_medium;
work_description = con_description;
display();
}
public function display() {
trace("display!");
var img_load:Loader = new Loader();
var img_request:URLRequest = new URLRequest(path);
addChild(img_load);
img_load.load(img_request);
}
}
}
This code resides in an external class named ArtWork.as.
The FLA that employs this class has an empty stage with one frame on the timeline, which contains the following…
import ArtWork;
var img:ArtWork = new ArtWork("screen.png");
Now, using the loader on the main timeline next to this code, I have been able to get content to display. Why isn’t it working from within my class file?
The trace call in display() within ArtWork.as IS being called, and after setting up IOError listeners for the loader I was unable to find any problems there.
If anybody could clear this issue up for me, I’d be very appreciative, as it’s currently posing a huge roadblock to my growth in AS3.