ActionScript 3 introduced new ways to load content and new types of content – now Flash can handle raw bytedata. This also increased the complexity of the process. You need a Loader, URLLoader, URLRequest, event listeners…
ContentLoader is a class that simplifies the process into a one class that can fulfill most of the basic needs:
– send and load data
– load bytedata
– load variables
– hande errors
– load images, mp3s, xml, text (JSON too, of course, but parsing is not supported)
Example:
//listeners _loader = new ContentLoader(); _loader.addEventListener(Event.COMPLETE, loader_INIT); _loader.addEventListener(ErrorEvent.ERROR, loader_ERROR); _loader.addEventListener(ProgressEvent.PROGRESS,loader_PROGRESS); _loader.addEventListener(Event.INIT, loader_INIT); _loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, loader_HTTP_STATUS); //load different media (there are more) _loader.loadText("variables.txt"); _loader.loadVariables("login.php",{name:"user",pwd:"kfj3i92dlakls"}); _loader.load("image.jpg"); // finished //if it was an image addChild(_loader.content); //if it was text var text = _loader.content; //if it was variables var var = _loader.content.variable; // clear the loader _loader.destroy(); _loader = null;
Kommentoi