I've been taking on a lot of responsibilities at work I normally wouldn't have anything to do with, as a result of that, I have been doing some Flash development lately. As a result I wrote some code I am proud of, not really because it's anything special, but just because I used to have such deep seeded fear of any Flash programming, and in two weeks I have completely re-written a file we use, which is now generated by dynamic xml for use with the latest version of actionscript for use on our entire intranet. I'm not going to explain it any more than it already is in the comments, just know that I liked what I did enough to document it. (and obviously, this is only the actionscript 3.0, the actual graphic part is not here, nor do I have the ability to post that)
(there's a scroll bar at the bottom of the frame, sorry, blogger apparently has shit for brains when it comes to formatting code)
//hard coded variables for testing directly in flash
//var myServer:String = "censore";
//var mySite:String = "/censored/";
//var mySubSiteID:String = "33";
//var myXML:String = "https://" + myServer + "/includes/headerXML.cfm?subsiteid=" + mySubSiteID;
var myServer:String = String(loaderInfo.parameters.server); //grabs server var from object embed
var mySite:String = ""; //creates var, set once xml is loaded
var mySubSiteID:String = String(loaderInfo.parameters.subSiteID); //grabs subsite var from object embed
var myXML:String = "/includes/headerXML.cfm?subsiteid=" + mySubSiteID; // creates full path to dynamic xml
var xmlLoader:URLLoader = new URLLoader(); //create new URLLoader Object
var xmlData:XML = new XML(); //create new xml data object
xmlLoader.addEventListener(Event.COMPLETE, LoadXML); //when the request is successful, call LoadXML function
xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, LoadXMLioError); //when the request fails, call LoadXMLioError function
xmlLoader.load(new URLRequest(myXML)); //start it up by calling our xml url
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data); //set data from file to our data object
ParseHeader(xmlData); //send data to our parser
}
function LoadXMLioError(e:IOErrorEvent):void {
myLargeText.text = e.text; //print error code to browser
}
function ParseHeader(xmlInput:XML):void {
//prints our values to the trace window during flash debugging
trace("-----------Start XML Output-------------");
trace(xmlInput.header.smalltext.text()[0]);
trace(xmlInput.header.maintext.text()[0]);
trace("------------End XML Output--------------");
myLargeText.text = xmlInput.header.maintext.text()[0]; //set the large text as defined by xml
myLargeTextShadow.text = xmlInput.header.maintext.text()[0]; //set the large text shadow as defined by xml
if(xmlInput.header.smalltext.text()[0] != "0"){ //make sure theres a value to get rid of the 'loading'
mySmallText.text = xmlInput.header.smalltext.text()[0].toUpperCase(); //set the small text as defined by xml
mySmallTextShadow.text = xmlInput.header.smalltext.text()[0].toUpperCase(); //set the small text shadow as defined by xml
} else { // no value? 86 it.
mySmallText.text = "";
mySmallTextShadow.text = "";
}
mySite = xmlInput.header.url.text()[0].toLowerCase(); //set the URL on the clickable area
}
backtomin.addEventListener(MouseEvent.CLICK, backtominHandler); //create evenlistener for a click on the button
function backtominHandler(event:MouseEvent):void {
navigateToURL(new URLRequest("/"), '_self'); // go back to root (THE MIN!)
trace("Action: Back to MIN"); //tell me what happens on debug
}
linkarea.addEventListener(MouseEvent.CLICK, linkareaHandler); //create evenlistener for a click on the link area
function linkareaHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(mySite), '_self'); // go to the URL defined earlier
trace("Action: Go to Current Page"); //tell me what happens on debug
}



0 comments:
Post a Comment