I have two classes, Init (which is my Document class) and LoadXML which… er… loads in some XML data.
Init calls the LoadXML and when it has completed a green backdrop is draw to the screen…
but…
Why do I need to put addChild in both classes before the green backdrop (a simple rectangle) will show up.
Init.as
package{
import flash.display.Sprite;
import flash.display.Stage;
public class Init extends Sprite{
// (*adminhost vars etc...*)
public function Init(){
var getPages = new LoadXML(adminhost,base,getposition,userRef);
addChild(getPages);
}
}
}
and
LoadXML.as
package
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.*;
import flash.net.*;
import flash.utils.*;
public class LoadXML extends Sprite
{
public function LoadXML(ah,bs,gp,ur)
{
var pageXMLloader:URLLoader = new URLLoader();
//loader.dataFormat = DataFormat.TEXT; //what is this?
pageXMLloader.addEventListener(Event.COMPLETE, onLoadSuccess);
pageXMLloader.load( new URLRequest(ah+bs+gp+"page_data.php?uRef="+ur));
}
private function onLoadSuccess(event:Event){
try{
var pagesXML:XML = new XML(event.target.data);
var pagesXMLList=pagesXML.children();
var numpages=pagesXMLList.length();
}
// At this point, example is ready to be used with E4X
//trace(pagesXML);
var makeRect:Sprite = new Sprite();
//makeRect.graphics.clear();
makeRect.graphics.beginFill(0x00FF00, .3);
makeRect.graphics.lineStyle(1, 0x000000, 1);
makeRect.graphics.drawRect(0,0,800,25);
makeRect.graphics.endFill();
makeRect.x = 0;
makeRect.y = 0;
addChild(makeRect);
} catch (e:TypeError) {
// If we get here, that means the downloaded text could
// not be converted into an XML instance, probably because
// it is not formatted correctly.
trace("Could not parse text into XML");
trace(e.message);
}
}
}
}
The XML loads in, no problems…
the confusing thing is why I need the addChild twice, once in each class - otherwise the green box doesn’t show, no matter which one I take it out of?
And if its twice is that two green boxes on top of each other being added to the stage?
one at depth 0 and one at depth 1?
any help would be appreciated?
Ikonik