I haven't used very much AS3 yet, but I thought I'd throw in this suggestion. In cases where you don't want to load a swf, but still want to add something to a Canvas which doesn't implement IUIComponent, could you not do it this way (it just seems like a bit less of a hack)
Using the
http://www.tcoz.com/flex/api/ example of an image and a canvas....
ActionScript Code:
public function SomeConstructor(){
var loader:Loader = new Loader();
var canvas:Canvas = new Canvas();
var uiComp:UIComponent = new UIComponent();
uiComp.addChild(loader);
this.addChild(canvas);
canvas.addChild(uiComp);
}
I knocked a test class together by following the loader example from the dictionary. I couldn't get the image to show using either "rawChildren"
or the above method (can someone enlighten me? I'm sure's it's something basic ) but all three methods did seem to output identical events at least:
initHandler: [Event type="init" bubbles=false cancelable=false eventPhase=2]
httpStatusHandler: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=0]
completeHandler: [Event type="complete" bubbles=false cancelable=false eventPhase=2]
Here's the class I used, in full:
ActionScript Code:
package
{
import flash.display.Loader;
import mx.containers.Canvas;
import flash.display.Sprite;
import mx.core.UIComponent;
import flash.events.*;
import flash.net.URLRequest;
public class Bob extends Sprite
{
private var url:String = "Image.gif";
public function Bob(){
var canvas:Canvas = new Canvas();
var loader:Loader = new Loader();
configureListeners(loader.contentLoaderInfo);
var request:URLRequest = new URLRequest(url);
loader.load(request);
var ui:UIComponent = new UIComponent();
ui.addChild(loader);
this.addChild(canvas);
canvas.addChild(ui);
}
private function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
dispatcher.addEventListener(Event.INIT, initHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
dispatcher.addEventListener(Event.OPEN, openHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
dispatcher.addEventListener(Event.UNLOAD, unLoadHandler);
}
private function completeHandler(event:Event):void {
trace("completeHandler: " + event);
}
private function httpStatusHandler(event:HTTPStatusEvent):void {
trace("httpStatusHandler: " + event);
}
private function initHandler(event:Event):void {
trace("initHandler: " + event);
}
private function ioErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}
private function openHandler(event:Event):void {
trace("openHandler: " + event);
}
private function progressHandler(event:ProgressEvent):void {
trace("progressHandler: bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
}
private function unLoadHandler(event:Event):void {
trace("unLoadHandler: " + event);
}
}
}