Loading XML into SWF with FlashVars
I really need help here. I hope someone can show me where I am going wrong.
I have a SWF which I embed in a html page with flashvars (see attached txt file)
I have three .as files from which I try to take the flashVars and use to pick up an XML file and colour in symbols on the SWF file plus show some text.
None of it works after spending days trawling through sites to find solutions.
Can someone help?
Below id the complete code. I'm running CS4/AS 3.0.
********************
HTML PAGE
********************
<html>
<head>
<title></title>
</head>
<body>
<p>Hello World!</p>
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="550" HEIGHT="400" id="8 - WHN Sixth Floor.swf" ALIGN="">
<param name="allowScriptAccess" value="sameDomain" />
<PARAM NAME=movie VALUE="8 - WHN Sixth Floor.swf">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#FFFFFF>
<PARAM NAME="FlashVars" value="xmlfile=myxml2.xml" />
<EMBED FlashVars="xmlfile=myxml2.xml" width="550" height="400" src="8 - WHN Sixth Floor.swf" allowScriptAccess="sameDomain" quality=high bgcolor=#FFFFFF NAME="8 - WHN Sixth Floor.swf" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>
</OBJECT>
</body>
</html>
********************
MAIN.AS
********************
package com
{
import com.*;
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.text.TextField;
import flash.display.Stage;
import flash.display.LoaderInfo;
import flash.events.*;
public class main extends MovieClip
{
public var gx:getXML;
public var xmlFileName:Object;
public function Main()
{
//addEventListener( Event.ADDED_TO_STAGE, init );
init();
}
private function init():void
{
//removeEventListener( Event.ADDED_TO_STAGE, init )
//var xmlFileName:Object = stage.loaderInfo.parameters;
var gx:getXML = new getXML("myxml2.xml");
addChild(gx);
}
}
}
********************
getXML.AS
********************
package com
{
// Static Class
import com.*;
import flash.display.SimpleButton;
import flash.xml.XMLDocument;
import flash.xml.XMLNode;
import flash.xml.XMLNodeType;
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLRequestMethod;
import flash.geom.ColorTransform;
import flash.net.navigateToURL;
import flash.system.fscommand;
public class getXML extends SimpleButton
{
public var xmlData:XML;
public function getXML(xmlurl:String):void
{
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, LoadXML);
var urlReq:URLRequest = new URLRequest(xmlurl);
//urlReq.method = URLRequestMethod.POST;
//var variables:URLVariables = new URLVariables();
//urlReq.data = variables;
//try {
loader.load(urlReq);
//} catch (error:Error) {
//trace ("Unable to load requested document.");
//}
}
public function LoadXML(e:Event):void
{
xmlData = new XML(e.target.data);
//xmlData = new XML("myxml2.xml");
var rslt:XMLDocument = new XMLDocument();
rslt.ignoreWhite = true;
rslt.parseXML(xmlData.toXMLString());
//trace(result.firstChild.childNodes.length);
for (var i=0; i<rslt.firstChild.childNodes.length; i++)
{
staticClass.head_Array.push(xmlData.data[i].head);
staticClass.color_code_Array.push(xmlData.data[i].colorcode);
staticClass.url_Array.push(xmlData.data[i].url);
staticClass.note_Array.push(xmlData.data[i].mc_name + "##" + xmlData.data[i].note);
staticClass.mc_Array.push(xmlData.data[i].mc_name);
}
var k = staticClass.mc_Array.length
var j = 0;
for each (var val:String in staticClass.mc_Array)
{
var btn:SimpleButton = SimpleButton(this.parent.getChildByName(val));
if (btn != null)
{
var rojo:ColorTransform = new ColorTransform();
rojo.color = uint (staticClass.color_code_Array[j]);
btn.transform.colorTransform = rojo;
btn.addEventListener(MouseEvent.CLICK, onClick);
btn.addEventListener(MouseEvent.MOUSE_OVER, onOver);
btn.addEventListener(MouseEvent.MOUSE_OUT, onOut);
/*
* Set mouse over separate colour
*/
btn.alpha = 3;
}
j++;
}
function onClick(e:MouseEvent )
{
trace(e.currentTarget.name + "----" + staticClass.url_Array[e.currentTarget.name.substring(7, e.currentTarget.name.length)-1]);
if(staticClass.url_Array[0] != "None")
{
navigateToURL(new URLRequest(staticClass.url_Array[0] + "?Room=" + e.currentTarget.name), "_self");
}
else
{
fscommand("RoomType", e.currentTarget.name);
}
}
function onOut(e:MouseEvent )
{
e.currentTarget.parent.getChildByName("HoverText") .text = "";
e.currentTarget.alpha = 3;
}
function onOver(e:MouseEvent )
{
e.currentTarget.alpha = 1.5;
for each (var val:String in staticClass.note_Array)
{
if(e.currentTarget.name == val.substring(0, val.indexOf("##", 0)))
{
e.currentTarget.parent.getChildByName("HoverText") .text = val.substring(val.indexOf("##", 0) + 2, val.length);
//e.currentTarget.parent.getChildByName("HoverText") .text = "HELP ME";
}
}
}
}
}
}
********************
staticClass.AS
********************
package com
{
import flash.display.MovieClip;
public class staticClass
{
public static var head_Array:Array = new Array();
public static var color_code_Array:Array = new Array();
public static var url_Array:Array = new Array();
public static var note_Array:Array = new Array();
public static var mc_Array:Array = new Array();
public static var url_Array1 :Array = new Array();
}
}