20 Replies Latest reply: Oct 29, 2011 7:29 PM by Beaastie RSS

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

    Beaastie

      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).

        • 1. Re: How to click button in exported SWF to go to frame in parent SWF?
          Beaastie Community Member

          Oh, I don't know if I made this clear, but the actual SWF loads fine, but when I click the button, it doesn't go back to a different frame in the parent SWF.

          • 2. Re: How to click button in exported SWF to go to frame in parent SWF?
            Peter Celuch Community Member

            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.

            • 3. Re: How to click button in exported SWF to go to frame in parent SWF?
              Peter Celuch Community Member

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

              • 4. Re: How to click button in exported SWF to go to frame in parent SWF?
                Beaastie Community Member

                Okay.... I tried deleting the whole Handler function (I didn't really know what that was anyway-- just saw it online...?)

                 

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

                So now for my parent SWF, my code is:

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

                 

                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);

                 

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

                for my exported SWF:

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

                 

                stop();

                 

                returnToAlbums_btn_inst.addEventListener(MouseEvent.CLICK, gotoAlbums);

                function gotoAlbums(event:MouseEvent):void {

                          parent.gotoAndStop(2);

                }

                 

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

                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);

                          }

                }

                • 5. Re: How to click button in exported SWF to go to frame in parent SWF?
                  Beaastie Community Member

                  Also, now there is no OUTPUT errors, but there is a COMPILER error on the export swf:

                   

                  Scene 1, Layer 'actionscript', Frame 2, Line 51061: Call to a possibly undefined method gotoAndStop through a reference with static type flash.display:DisplayObjectContainer.
                  • 6. Re: How to click button in exported SWF to go to frame in parent SWF?
                    Peter Celuch Community Member

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

                    • 7. Re: How to click button in exported SWF to go to frame in parent SWF?
                      Beaastie Community Member

                      on the parent swf:

                      -----------

                       

                      stop();

                       

                      cutLimestone_btn_inst.addEventListener(MouseEvent.CLICK, gotoCutLimestone);

                      function gotoCutLimestone(event:MouseEvent):void {

                                gotoAndStop("cutLimestone_btn_frame");

                      }

                       

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

                      on the export swf:

                      --------

                       

                      stop();

                       

                      returnToAlbums_btn_inst.addEventListener(MouseEvent.CLICK, gotoAlbums);

                      function gotoAlbums(event:MouseEvent):void {

                                parent.gotoAndStop(2);

                      }

                      • 8. Re: How to click button in exported SWF to go to frame in parent SWF?
                        Peter Celuch Community Member

                        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);
                        
                        • 9. Re: How to click button in exported SWF to go to frame in parent SWF?
                          Beaastie Community Member

                          Export SWF works without error now, but parent SWF returns:

                           

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

                           

                          TypeError: Error #2007: Parameter child must be non-null.

                                    at flash.display::DisplayObjectContainer/addChild()

                                    at Main/frame3()

                                    at flash.display::MovieClip/gotoAndStop()

                                    at Main/gotoCutLimestone()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

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

                                    at Main/preload1()

                           

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

                           

                          under OUTPUT when I try to load the SWF.  The returnToAlbums_btn_inst doesn't work still either.

                          • 10. Re: How to click button in exported SWF to go to frame in parent SWF?
                            Peter Celuch Community Member

                            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);
                                      }
                            }
                            
                            • 11. Re: How to click button in exported SWF to go to frame in parent SWF?
                              Beaastie Community Member

                              where do i put this? i don't have a preload1 function

                              • 12. Re: How to click button in exported SWF to go to frame in parent SWF?
                                Peter Celuch Community Member

                                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);

                                          }

                                }

                                • 13. Re: How to click button in exported SWF to go to frame in parent SWF?
                                  Beaastie Community Member

                                  Okay, now the OUTPUT error says:

                                   

                                  TypeError: Error #2007: Parameter child must be non-null.

                                            at flash.display::DisplayObjectContainer/addChild()

                                            at Main/frame3()

                                            at flash.display::MovieClip/gotoAndStop()

                                            at Main/gotoCutLimestone()

                                  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()

                                   

                                  and it doesn't even load the export swf.

                                  • 14. Re: How to click button in exported SWF to go to frame in parent SWF?
                                    Peter Celuch Community Member

                                    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!

                                    • 15. Re: How to click button in exported SWF to go to frame in parent SWF?
                                      Beaastie Community Member

                                      Okay, now the SWF loads fine, but output errors:

                                      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()

                                       

                                      And the returnToAlbums_btn_inst still isn't working...

                                      • 16. Re: How to click button in exported SWF to go to frame in parent SWF?
                                        Peter Celuch Community Member

                                        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);
                                        
                                             }
                                        
                                        }
                                        
                                        
                                        • 17. Re: How to click button in exported SWF to go to frame in parent SWF?
                                          Beaastie Community Member

                                          Didn't work.  I'll send you both files.

                                          • 18. Re: How to click button in exported SWF to go to frame in parent SWF?
                                            Beaastie Community Member

                                            Okay, I'm officially an idiot.  How do I send you the files? I tried sending you a private message but it wouldn't let me attach anything.

                                            • 19. Re: How to click button in exported SWF to go to frame in parent SWF?
                                              Peter Celuch Community Member

                                              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!