Loading an External SWF Files not working
Hello,
So I have a project I am working on in which I would like to teach how to cash a scratch off card. I have made the scratch and made it so it will "scratch"
Before: After:


Now I have saved this out and am trying to load this into my "holder" however I am getting an error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at ScratchTicket()
When I use this code:
stop();
import flash.events.MouseEvent;
nextPG_btn.addEventListener(MouseEvent.CLICK, nClick);
lastPG_btn.addEventListener(MouseEvent.CLICK, lClick);
function nClick(event:MouseEvent):void{
nextFrame();
}
function lClick(event:MouseEvent):void{
gotoAndStop(3);
}
var mcExt:MovieClip;
var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);
ldr.load(new URLRequest("ScratchTicketOnly.swf"));
function swfLoaded(e:Event):void {
mcExt = MovieClip(ldr.contentLoaderInfo.content);
ldr.contentLoaderInfo.removeEventListener(Event.COMPLETE, swfLoaded);
mcExt.x = 50;
mcExt.y = 50;
addChild(mcExt);
}
What am I doing wrong?
Is it because of my coding in the External SWF?
package {
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.ui.Mouse;
public class ScratchTicket extends MovieClip{
var scratcherIsActive:Boolean= false;
var stuffUnderMask:Sprite = new Sprite();
// init class
public function ScratchTicket():void{
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseIsDown);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseIsMoving);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseIsUp);
// make mask
stuffUnderMaskClip.mask = stuffUnderMask;
addChild(stuffUnderMask);
makeCursor();
}
// helper functions
private function makeCursor():void{
trace("Custom cursor can go here");
}
// hover effects
private function mouseIsDown(e:MouseEvent):void{
//Mouse.hide();
Mouse.cursor="hand";
scratcherIsActive = true;
}
private function mouseIsUp(e:MouseEvent):void{
//Mouse.show();
Mouse.cursor="arrow";
scratcherIsActive = false;
}
private function mouseIsMoving(e:MouseEvent):void{
if(scratcherIsActive){
stuffUnderMask.graphics.beginFill(0x000000);
stuffUnderMask.graphics.drawEllipse(mouseX, mouseY,60, 60);
stuffUnderMask.graphics.endFill();
}
}
}// class
}// package
Any help is great!