I want to dynamically load the graphic of the button into an mc inside each frame of the button (up and over). Inside each frame I have a movie clip (canvas and canvas_over)
The green box is the button object (header_btn):
This is my code:
var hLoader:Loader = new Loader();
hLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, hLoaded);
hLoader.load(new URLRequest("http://django.liveproject.is/misc/current_flash_header/image.png"));
function hLoaded(event:Event):void {
var image:Bitmap = new Bitmap(event.target.content.bitmapData);
header_btn.canvas.addChild(image);
}
var hoLoader:Loader = new Loader();
hoLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, hoLoaded);
hoLoader.load(new URLRequest("http://django.liveproject.is/misc/current_flash_header_over/image.png"));
function hoLoaded(event:Event):void {
var image:Bitmap = new Bitmap(event.target.content.bitmapData);
header_btn.over_canvas.addChild(image);
}
The error I get is:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MethodInfo-78()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MethodInfo-77()
Edit - Solved:
header_canvas
and header_canvas_over
are placed on stage. header_canvas_over
is placed over header_canvas
.
Code:
var context:LoaderContext = new LoaderContext();
context.checkPolicyFile = true;
var hLoader:Loader = new Loader();
hLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, hLoaded);
hLoader.load(new URLRequest("http://django.liveproject.is/misc/current_flash_header/image.png"), context);
function hLoaded(event:Event):void {
var image:Bitmap = new Bitmap(event.target.content.bitmapData);
header_canvas_up.addChild(image);
}
var hoLoader:Loader = new Loader();
hoLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, hoLoaded);
hoLoader.load(new URLRequest("http://django.liveproject.is/misc/current_flash_header_over/image.png"), context);
function hoLoaded(event:Event):void {
var image:Bitmap = new Bitmap(event.target.content.bitmapData);
header_canvas_over.addChild(image);
header_canvas_over.visible = false;
header_btn.addEventListener(MouseEvent.MOUSE_OVER, onHover);
function onHover(event:Event):void {
header_canvas_over.visible = true;
}
header_btn.addEventListener(MouseEvent.MOUSE_OUT, onOut);
function onOut(event:Event):void {
header_canvas_over.visible = false;
}
}
It would be nice though if as3 allowed for buttons to contain objects. :/