Skip to main content
Participant
December 6, 2007
Question

Need Help With AS3

  • December 6, 2007
  • 4 replies
  • 339 views
I'm creating a graphic loader at runtime but I can't set the height or width of the loader. I can set the x and y but when I put the code for height and width the graphic doesn't display. I don't get any errors, it just doesn't display. Here is the code:

var mainXML:XML;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("CBT_Template.xml"));

var smartGraphicLoader:Loader = new Loader();
var smartGraphicFile:String = "tough love";
var smartGraphicFileReq:URLRequest;

function onComplete(evt:Event)
{
mainXML = new XML(loader.data)
tb.htmlText = mainXML.CBT_Template[0].objective;
tl.htmlText = mainXML.CBT_Template[0].objective;
tb1.text = mainXML.CBT_Template[0].header;
tb2.text = mainXML.CBT_Template[0].explanation;
ta.htmlText = mainXML.CBT_Template[0].objective;
LoadSmartGraphic();

}

function LoadSmartGraphic() {
smartGraphicFile = mainXML.CBT_Template[0].graphic;
//OurTextBox.htmlText = lessonInfoXML.lesson[0].segment[0].page[CurrentPage - 1].explanation;
smartGraphicFileReq = new URLRequest(smartGraphicFile);
//smartGraphicLoader.addEventListener(Event.COMPLETE, completeHandler);
smartGraphicLoader.load(smartGraphicFileReq);
addChild(smartGraphicLoader);
//trace(smartGraphicFile);
smartGraphicLoader.x = 0;
smartGraphicLoader.y = 0;
smartGraphicLoader.height = 50; //here is where the code prevents the graphic from loading.
smartGraphicLoader.width = 50; //it works fine without these two lines but i need to set the height and width
This topic has been closed for replies.

4 replies

Inspiring
December 6, 2007
I'm sure folks can offer some more insight, but looking at this, it looks as if you are trying to add the loader itself to the stage, rather than the content that it loads. There should be a handler that waits for the load that you call to complete(I usually use Event.INIT), and then makes a display object out of the content that is loaded. I can't really test this code, since I am not totally sure how your XML data is formatted, or what exactly is being loaded but:
bdq1772Author
Participant
December 6, 2007
The code worked perfectly. Thanks!!!
Inspiring
December 6, 2007
Grr... not a good day

smartGraphicLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
sgLoadHandler);



Inspiring
December 6, 2007
Sorry. That post was mostly incorrect.

But you still need to wait for the load to complete before resizing:

function LoadSmartGraphic() {
smartGraphicFile = mainXML.CBT_Template[0].graphic;
smartGraphicFileReq = new URLRequest(smartGraphicFile);
smartGraphicLoader.addEventListener(Event.COMPLETE, sgLoadHandler); //<--
HERE
smartGraphicLoader.load(smartGraphicFileReq);
addChild(smartGraphicLoader);
smartGraphicLoader.x = 0;
smartGraphicLoader.y = 0;
}

function sgLoadHandler(evt:Event)
{
smartGraphicLoader.height = 50;
smartGraphicLoader.width = 50;
}


Inspiring
December 6, 2007
Add the listener to the contentLoaderInfo:

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);