Skip to main content
Participant
March 23, 2012
Answered

Loading an External SWF Files not working

  • March 23, 2012
  • 1 reply
  • 704 views

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!

This topic has been closed for replies.
Correct answer sinious

Make sure you check for errors on loading..

import flash.events.IOErrorEvent;

ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, uhOhError);

function uhOhError(e:Event):void

{

     trace(e);

     // probably put some visual text field here to display the error

}

Aside that, on the first block of code mentioned, is that a frame script or running from somewhere in a class? If in a class and it doesn't extend a display object then you can't addChild(mcExt) without erroring.

1 reply

sinious
siniousCorrect answer
Legend
March 23, 2012

Make sure you check for errors on loading..

import flash.events.IOErrorEvent;

ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, uhOhError);

function uhOhError(e:Event):void

{

     trace(e);

     // probably put some visual text field here to display the error

}

Aside that, on the first block of code mentioned, is that a frame script or running from somewhere in a class? If in a class and it doesn't extend a display object then you can't addChild(mcExt) without erroring.