Skip navigation
Beaastie
Currently Being Moderated

How to click button in exported SWF to go to frame in parent SWF?

Oct 29, 2011 3:54 PM

I looked online, but couldn't find anything helpful.   I got these codes on the web, but they're not working.... (I'm pretty new to flash).

 

-----------------------------------------------

projectgallery.swf - PARENT SWF

projectgallery_cutLimestone.swf - EXPORT SWF

returnToAlbums_btn_inst - instance of a button on the export swf that I want to be able to click to go to a different frame in the parent SWF

 

___________________________

 

Here are my codes:

 

------------------------------------------------

 

on the parent SWF:

 

import flash.display.MovieClip;

import flash.events.MouseEvent;

 

 

var myLoader:Loader = new Loader();

var url:URLRequest = new URLRequest("projectgallery_cutlimestone.swf");

myLoader.load(url);

 

 

function loadHandler (event:Event) {

 

          var projectgallery_cutlimestone:MovieClip = event.target.content;

          addChild(myLoader);

          trace(projectgallery_cutlimestone);

 

          function returnToAlbums (event:MouseEvent):void {

                    projectgallery_cutlimestone.returnToAlbums_btn_inst.play();

          }

 

          projectgallery_cutlimestone.addEventListener(MouseEvent.CLICK, returnToAlbums);

}

 

 

 

myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadHandler );

 

---------------------------------------------

 

When I try it, the SWF loads fine, but when it loads, this OUTPUT error appears:

 

[object Main]

TypeError: Error #1009: Cannot access a property or method of a null object reference.

          at Main/frame2()

          at flash.display::MovieClip/gotoAndStop()

          at Main/preload1()

 

--------------------------------------------------

then, when I try to click the button returnToAlbums_btn_inst, this OUTPUT error appears:

 

ReferenceError: Error #1069: Property play not found on flash.display.SimpleButton and there is no default value.

          at Function/<anonymous>()

 

 

 

 

 

 

-------------------------------------------------

I'm really new to flash, so I don't know why it's not working.  The instance is labeled (I double-checked).

 
Replies
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Oct 29, 2011 4:08 PM   in reply to Beaastie

    ReferenceError: Error #1069: Property play not found on flash.display.SimpleButton and there is no default value.

              at Function/<anonymous>()

     

    How did you define button's click handler? It seems like you are commanding the button itself to play(), not its parent.

     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Oct 29, 2011 4:09 PM   in reply to Peter Celuch

    I would like to see also whole code of the object which contains function preload(). (Main)

     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Oct 29, 2011 4:18 PM   in reply to Beaastie

    show me frame script there: Scene 1, Layer 'actionscript', Frame 2

     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Oct 29, 2011 4:36 PM   in reply to Beaastie

    in export swf, frame2:

     

    parent.gotoAndStop(2);
    

     

    should be

     

    MovieClip(parent).gotoAndStop(2); //because "parent" is too vague: DisplayObjectContainer, not MovieClip.
    

     

    And in parent swf, try

     

    addChild(myLoader.content);
    

     

    instead of

     

    addChild(myLoader);
    
     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Oct 29, 2011 5:07 PM   in reply to Beaastie

    change preload1() to

     

    function preload1(e:Event):void{
              var total_bytes:Number = loaderInfo.bytesTotal;
              var loaded_bytes:Number = loaderInfo.bytesLoaded;
              if (total_bytes==loaded_bytes){
              gotoAndStop(2);
              this.removeEventListener(Event.ENTER_FRAME, preload1);
              }
    }
    
     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Oct 29, 2011 5:58 PM   in reply to Beaastie

    Yes you do

    It's the one that's generating tons of errors you just posted.

     

    Beaastie wrote:

    -----------------------------

    by the function preload do you mean the one that originally preloads my parent swf on frame 1?  here's that:

    ---------------------------------

     

    import flash.events.Event;

     

     

    stop();

     

     

    this.addEventListener(Event.ENTER_FRAME, preload1);

     

     

    function preload1(e:Event):void{

              var total_bytes:Number = this.stage.loaderInfo.bytesTotal;

              var loaded_bytes:Number = this.stage.loaderInfo.bytesLoaded;

              if (total_bytes==loaded_bytes){

              gotoAndStop(2);

              this.removeEventListener(Event.ENTER_FRAME, preload1);

              }

    }

     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Oct 29, 2011 6:13 PM   in reply to Beaastie

    The handler funciton you deleted in parent wasn't useless.. we'll have to put it back. With some modifications..

     

    change parent code from

     

    import flash.display.MovieClip;
    import flash.events.MouseEvent;
     
    var myLoader:Loader = new Loader();
    var url:URLRequest = new URLRequest("projectgallery_cutlimestone.swf");
    myLoader.load(url);
    addChild(myLoader.content);
    

     

    to

     

    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.events.Event;
     
    var myLoader:Loader = new Loader();
    var url:URLRequest = new URLRequest("projectgallery_cutlimestone.swf");
    myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteHandler);
    myLoader.load(url);
     
    function loadCompleteHandler(event:Event):void {
         addChild(myLoader.content);
    }
    

     

    Fingers crossed!

     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Oct 29, 2011 6:30 PM   in reply to Beaastie

    Oh my. Let's try one more thing, if it doesn't work, pack the whole project and send me link via private message.

     

    change parent one more time:

     

    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.events.ProgressEvent;
     
    var myLoader:Loader = new Loader();
    var url:URLRequest = new URLRequest("projectgallery_cutlimestone.swf");
    myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgressHandler);
    myLoader.load(url);
     
    function loadProgressHandler(event:Event):void {
         if(myLoader.content) {
              addChild(myLoader.content);
              myLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, loadProgressHandler);
     
         }
     
    }
     
    
     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Oct 29, 2011 7:21 PM   in reply to Beaastie

    OK, fixed.

     

    The main problem was in naming your Document classes. In both files, the Document class was Main. Flashplayer caches all class definitions so they can be reused and shared between loaded swfs. This is really useful feature if you're aware of it. Otherwise it can cause quite a headache. The errors seem to pop out for no apparent reason etc. I renamed the Document class of first swf to Index. Make sure you never ever have two document classes with the same name. You should change the Main also to CutLimestone if you plan on loading other galleries.

     

    I also made some smaller changes - make sure to copy them to new galleries so they all behave the same.

     

    Good luck!

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points