February 15th, 2010 — 9:05am
The following article assumes you have a solid understanding of Flash AS2 and the Flash interface, and skips all basic Flash setup instructions and explanations in effort to provide you with quick, concise information. It also assumes you have images ready to be loaded into your swf.
The AS2 refresher series aims to consolidate basic, everyday snippets for the most common tasks used by Flash developers working with legacy files. Basic explanations are included in the comments, since after all, who wants to read through a bunch of crap when you are just after the code? Enjoy.
AS2 sendAndLoad with LoadVars Snippet:
-
// variables
-
//——————————————————————————————————————————-
-
-
// create a var to hold the name of the bitmap we want to load
-
var imageName:String = "image1.jpg";
-
-
// set a reference to the folder your images are in ›› the slash (images/) is added below when we assemble the path
-
var imagePath:String = "images";
-
-
// set a new MovieClipLoader and immediately load the image into a movieclip on the stage named ‘container_mc’
-
var mcLoader:MovieClipLoader = new MovieClipLoader();
-
mcLoader.addListener(this);
-
mcLoader.loadClip(imagePath + "/" + imageName, container_mc);
-
-
// functions
-
//——————————————————————————————————————————-
-
-
// when the image has loaded, begin the ad unit animation
-
function onLoadComplete(mc:MovieClip) {
-
-
trace("image loaded from: " + imagePath + "/" + imageName);
-
trace("image loaded into: " + mc);
-
-
// load has completed, call init() and start the app
-
init();
-
}
-
-
// called while image is loading ›› insert preloading actions here
-
function onLoadProgress():Void {
-
-
trace("image loading…");
-
}
-
-
function init():Void {
-
-
// start your app
-
-
// for additional progress event listeners associated with loading external bitmaps,
-
// visit: http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001381.html
-
}
Comment » | Flash AS2
January 22nd, 2010 — 2:19pm
The following article assumes you have a solid understanding of Flash AS2 and the Flash interface and skips all basic Flash setup instructions and explanations in effort to provide you with quick, concise information. It also assumes you are dealing with a server-side script that is set up to receive parameters and send back a response.
The AS2 refresher series aims to consolidate basic, everyday snippets for the most common tasks used by Flash developers working with legacy files. Basic explanations are included in the comments, since after all, who wants to read through a bunch of crap when you are just after the code? Enjoy.
AS2 sendAndLoad with LoadVars Snippet:
-
// variables
-
//——————————————————————————–
-
-
// set a ref to hold your URL
-
var myURL:String = "test.html";
-
-
// set a new LoadVars object
-
var result_lv:LoadVars = new LoadVars();
-
-
// function that fires when a result is received from the server
-
result_lv.onLoad = function(success:Boolean) {
-
-
if (success) {
-
-
trace ("——————————————————-")
-
trace (">>>>> SUCCESS!");
-
trace ("——————————————————-")
-
-
} else {
-
-
trace ("——————————————————-")
-
trace (">>>>> ERROR!");
-
trace ("——————————————————-")
-
}
-
};
-
-
// instantiate a new LoadVars object
-
var myLoadVars:LoadVars = new LoadVars();
-
-
// assign parameters to the object
-
myLoadVars.var1 = "Robots";
-
myLoadVars.var2 = "Aliens";
-
-
// send our variables to the value in myURL and await the response which will be caught by ‘result_lv.onLoad’
-
myLoadVars.sendAndLoad(myURL, result_lv, "POST");
-
-
// make sure your URL is configured correctly by tracing out the compiled syntax
-
trace("posting to: " + myURL + "?var1=" + myLoadVars.var1 + "&var2=" + myLoadVars.var2);
Comment » | Flash AS2
January 12th, 2010 — 11:23am
The following article assumes you have a solid understanding of Flash AS2 and the Flash interface and skips all basic Flash setup instructions and explanations in effort to provide you with quick, concise information. It also assumes you are dealing with a server-side script that is set up to receive parameters and send back XML.
The AS2 refresher series aims to consolidate basic, everyday snippets for the most common tasks used by Flash developers working with legacy files. Basic explanations are included in the comments, since after all, who wants to read through a bunch of crap when you are just after the code? Enjoy.
AS2 sendAndLoad XML Snippet:
-
// variables
-
//——————————————————————————–
-
-
// set a ref to hold your URL
-
var myURL:String = "test.html";
-
-
// set a new XML object
-
var myXML:XML = new XML();
-
myXML.ignoreWhite = true;
-
myXML.onLoad = onMyXMLLoad;
-
-
// functions
-
//——————————————————————————–
-
-
// runs when the xml is successfully loaded from the url
-
function onMyXMLLoad(success:Boolean) {
-
-
if (success) {
-
-
trace("XML LOADED FROM SERVER");
-
-
// xml has been loaded, call init()
-
init();
-
-
} else {
-
-
trace("ERROR: XML NOT LOADED FROM SERVER");
-
}
-
}
-
-
// function that runs after the XML has been returned and loaded from the server
-
function init():Void {
-
-
trace("init() called");
-
trace("");
-
-
trace("myXML: \n" + myXML);
-
}
-
-
// load vars
-
//——————————————————————————–
-
-
// set a new LoadVars object
-
var myLoadVars:LoadVars = new LoadVars();
-
-
// assign parameters to the object
-
myLoadVars.var1 = "Michael";
-
myLoadVars.var2 = "Becker";
-
-
// send our variables to the value in myURL and await the response which will be stored in myXML
-
myLoadVars.sendAndLoad(myURL, myXML, "POST");
-
-
// make sure your URL is configured correctly by tracing out the compiled syntax
-
trace("posting to: "+ myURL + "?var1=" + myLoadVars.var1 + "&var2=" + myLoadVars.var2);
Comment » | Flash AS2, XML