12 Replies Latest reply on Oct 12, 2009 11:51 AM by dustycoats

    How do I loadMovie in as3?

    dustycoats Level 1

      I need swfs to load in an HTML file.  I used to simply use the loadMovie script in AS2 but it seems very difficult in AS3.  I tried this way bbut it gave me errors.  Any ideas?  thanks for your time on this.

       

       

       

      stop();

       

      import flash.events.MouseEvent;

       

      var i:int;
      var mySwfs:Array = [story_2.swf, story_3.swf, story_4.swf, story_5.swf];
      var myLoader:Loader = new Loader();
      var myRequest:URLRequest;

       

                 
      myBtn_next.addEventListener(MouseEvent.CLICK, nextBtnClick);
      myBtn_back.addEventListener(MouseEvent.CLICK, backBtnClick);

       

      myBtn_back.gotoAndStop(2);

       


      function backBtnClick(event:MouseEvent):void
      {
           loadSwf(--i);
      }

       


      function nextBtnClick(event:MouseEvent):void
      {
           loadSwf(i++);
      }

       

      function loadSwf(index:int):void
      {
           var url = mySwfs[index];
           myRequest = new URLRequest(url);
           myLoader.load (myRequest);
           myLoader.contentLoaderInfo.addEventListener(Progr essEvent.PROGRESS, loadProgress);
           myLoader.contentLoaderInfo.addEventListener(Event .COMPLETE, loadComplete);
           checkButtons();
      }

       

      function checkButtons():void
      {
          
           if (i == mySwfs.length)
           {
                myBtn_next.gotoAndS top(2);
           }
           else
           {
                myBtn_next.gotoAndS top(1);
           }
          
           if(i > 0)
           {
                myBtn_back.gotoAndS top(1);
           }
           else
           {
                myBtn_back.gotoAndS top(2);
           }
      }

       

       

       

      function loadProgress(evt:ProgressEvent):void
      {
           var amountLoaded:Number = evt.bytesLoaded/evt.bytesTotal;
           amountLoaded = Math.round(amountLoaded * 100);
      }

       


      function loadComplete(evt:Event):void
      {
           container.addChild(myLoader);
      }

        • 1. Re: How do I loadMovie in as3?
          Ned Murphy Adobe Community Professional & MVP

          You should include the error message you are getting as they will help to determine where your errors are.  One that I see off the top is that you ned to assign the mySwfs array values as strings...

           

          var mySwfs:Array = ["story_2.swf", "story_3.swf", "story_4.swf", "story_5.swf"];

           

          And while you don't need to invent the url variable, you should define its class like any other var you declare...

           

          var url:String = mySwfs[index];

          1 person found this helpful
          • 2. Re: How do I loadMovie in as3?
            dustycoats Level 1

            Thanks that got rid of a bunch but I stil get this one

             

            1071: Syntax error: expected a definition keyword (such as function) after attribute avr, not url.

            • 3. Re: How do I loadMovie in as3?
              dustycoats Level 1

              Ok fixed that one but I get the old ones back now.  i cannot seem to cut and paste the entirecompiled  errors.

              • 4. Re: How do I loadMovie in as3?
                dustycoats Level 1

                HI Ned,

                 

                thanks for looking a this.  I am the guy trying to do what used to be a

                simple LoadMovie code but get these errors.  I am not able to hang with as3,

                way over my head I think where as as2 used to work for me.

                 

                1120: Access of undefined property myBtn_next.

                1120: Access of undefined property myBtn_next.

                1120: Access of undefined property myBtn_back.

                1120: Access of undefined property myBtn_back.

                1120: Access of undefined property index.

                1188: Illegal assignment to class String.

                1120: Access of undefined property myBtn_next.

                1120: Access of undefined property myBtn_back.

                1120: Access of undefined property myBtn_back.

                 

                stop();

                 

                import flash.events.MouseEvent;

                 

                var i:int;

                var mySwfs:Array = ["time_2.swf", "time_3.swf", "time_4.swf", "time_5.swf"];

                var myLoader:Loader = new Loader();

                var myRequest:URLRequest;

                var url;String = mySwfs[index];

                           

                myBtn_next.addEventListener(MouseEvent.CLICK, nextBtnClick);

                myBtn_back.addEventListener(MouseEvent.CLICK, backBtnClick);

                 

                myBtn_back.gotoAndStop(2);

                 

                 

                function backBtnClick(event:MouseEvent):void

                {

                     loadSwf(--i);

                }

                 

                 

                function nextBtnClick(event:MouseEvent):void

                {

                     loadSwf(i++);

                }

                 

                function loadSwf(index:int):void

                {

                     var url = mySwfs[index];

                     myRequest = new URLRequest(url);

                     myLoader.load (myRequest);

                     myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,

                loadProgress);

                     myLoader.contentLoaderInfo.addEventListener(Event .COMPLETE,

                loadComplete);

                     checkButtons();

                }

                 

                function checkButtons():void

                {

                     

                     if (i == mySwfs.length)

                     {

                          myBtn_next.gotoAndStop(2);

                     }

                     else

                     {

                          myBtn_next.gotoAndStop(1);

                     }

                     

                     if(i > 0)

                     {

                          myBtn_back.gotoAndStop(1);

                     }

                     else

                     {

                          myBtn_back.gotoAndStop(2);

                     }

                }

                 

                 

                 

                function loadProgress(evt:ProgressEvent):void

                {

                     var amountLoaded:Number = evt.bytesLoaded/evt.bytesTotal;

                     amountLoaded = Math.round(amountLoaded * 100);

                }

                 

                 

                function loadComplete(evt:Event):void

                {

                     container.addChild(myLoader);

                }

                • 5. Re: How do I loadMovie in as3?
                  Ned Murphy Adobe Community Professional & MVP

                  For all of those button related errors I would say that you either did not assign those particular instance names to them (via the properties panel), or the buttons are not present when that code executes.

                   

                  For the other error, I suspect it has to do with one of the two lines below...

                   

                  var url;String = mySwfs[index]; // this line has a semicolon where a colon should be

                   

                  function loadSwf(index:int):void

                  {

                       var url = mySwfs[index]; // this line either needs to look exactly like the first above, or needs to get rid of the "var"

                   

                  By declaring the var in the function, the two url variables are not the same variable.  If you remove it, the one inside the function will be the one outside.

                   

                  As far as the "index" related error goes, I think it may be the first line I mention above.  index is not defined at that point, but you use it

                   

                  If you go into your Publish Settings and select the option to Permit Debugging, your error messages will likely provide line number information as to where the errors are.

                  1 person found this helpful
                  • 6. Re: How do I loadMovie in as3?
                    dustycoats Level 1

                    Ok, I miss-labeled my btns so corrected that, changed semi colon to a colon

                    and all compiling errors seem to be gone. I am getting closer and understand

                    a bit more.  Now I get:

                     

                    ReferenceError: Error #1065: Variable index is not defined.

                        at time_2_fla::MainTimeline/frame1()[time_2_fla.MainTimeline::frame1:9]

                     

                    Is the index my home HTML doc? How do I define that?  And what is it asking

                    about the time_2.fla?

                     

                     

                    Thanks for working with me.

                    • 7. Re: How do I loadMovie in as3?
                      ASnewbie

                      Your problem is fairly simple and the error tells it all.

                      at time_2_fla::MainTimeline/frame1()[time_2_fla.MainTimeline::frame1:9]

                      :9 means that you need to look at line 9

                       

                       

                       

                      var i:int;

                      var mySwfs:Array = ["time_2.swf", "time_3.swf", "time_4.swf", "time_5.swf"];

                      var myLoader:Loader = new Loader();

                      var myRequest:URLRequest;

                      var url;String = mySwfs[index];

                       

                      You must have already changed it to

                      var url:String = mySwfs[index];

                      but index is still not defined

                       

                      so you must define index before using it in the line above. such as

                      var index:int=1;

                      var url:String = mySwfs[index]

                       

                      Point to note here is that you should avoid using keyword/names as variables names and index is one of them.

                       

                      Best Regards,

                      Murtuza

                      http://www.sowebme.com/murtaza

                      • 8. Re: How do I loadMovie in as3?
                        dustycoats Level 1

                        I keep thinking it is easy myself as it used to be very simple in as2. But

                        this has been killing me.

                         

                        Now I am getting this:

                         

                        ReferenceError: Error #1069: Property gotoAndStop not found on

                        flash.display.SimpleButton and there is no default value.

                            at time_2_fla::MainTimeline/frame1()[time_2_fla.MainTimeline::frame1:16]

                         

                         

                        Line 16 is          myBtn_back.gotoAndStop(2);

                         

                         

                         

                         

                        Code is below, thanks much

                         

                         

                        stop();

                         

                        import flash.events.MouseEvent;

                         

                        var i:int;

                        var mySwfs:Array = ["time_2.swf", "time_3.swf", "time_4.swf", "time_5.swf"];

                        var myLoader:Loader = new Loader();

                        var myRequest:URLRequest;

                        var index:int=1;

                        var url:String = mySwfs[index];

                         

                                   

                        myBtn_next.addEventListener(MouseEvent.CLICK, nextBtnClick);

                        myBtn_back.addEventListener(MouseEvent.CLICK, backBtnClick);

                         

                        myBtn_back.gotoAndStop(2);

                         

                         

                        function backBtnClick(event:MouseEvent):void

                        {

                             loadSwf(--i);

                        }

                         

                         

                        function nextBtnClick(event:MouseEvent):void

                        {

                             loadSwf(i++);

                        }

                         

                        function loadSwf(index:int):void

                        {

                             url = mySwfs[index];

                             myRequest = new URLRequest(url);

                             myLoader.load (myRequest);

                             myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,

                        loadProgress);

                             myLoader.contentLoaderInfo.addEventListener(Event .COMPLETE,

                        loadComplete);

                             checkButtons();

                        }

                         

                        function checkButtons():void

                        {

                             

                             if (i == mySwfs.length)

                             {

                                  myBtn_next.gotoAndStop(2);

                             }

                             else

                             {

                                  myBtn_next.gotoAndStop(1);

                             }

                             

                             if(i > 0)

                             {

                                  myBtn_back.gotoAndStop(1);

                             }

                             else

                             {

                                  myBtn_back.gotoAndStop(2);

                             }

                        }

                         

                         

                         

                        function loadProgress(evt:ProgressEvent):void

                        {

                             var amountLoaded:Number = evt.bytesLoaded/evt.bytesTotal;

                             amountLoaded = Math.round(amountLoaded * 100);

                        }

                         

                         

                        function loadComplete(evt:Event):void

                        {

                             container.addChild(myLoader);

                        }

                        • 9. Re: How do I loadMovie in as3?
                          ASnewbie Level 1

                          What is this line trying to do?

                          Im sure that myBtn_back is a button and behaves as a button so there is no gotoAndStop(2) for buttons.

                           

                          myBtn_back.gotoAndStop(2);

                           

                          You just have to remove that line above and it should work

                           

                          BR

                          Murtuza

                          http://www.sowebme.com/murtaza

                          • 10. Re: How do I loadMovie in as3?
                            dustycoats Level 1

                            Huh? That was a wierd experience.  I made those changes and there were no

                            compiling or other errors but it did not work then it crashed and I cannot

                            open it.  I luckily had the code pasted and put it in another file and now

                            get this which I did not get before.

                             

                            1061: Call to a possibly undefined method gotoAndStop through a reference

                            with static type flash.display:SimpleButton.

                             

                            1061: Call to a possibly undefined method gotoAndStop through a reference

                            with static type flash.display:SimpleButton.

                             

                            1061: Call to a possibly undefined method gotoAndStop through a reference

                            with static type flash.display:SimpleButton.

                             

                            1061: Call to a possibly undefined method gotoAndStop through a reference

                            with static type flash.display:SimpleButton.

                             

                            1120: Access of undefined property container.

                             

                            With the code below.

                             

                            stop();

                             

                            import flash.events.MouseEvent;

                             

                            var i:int;

                            var mySwfs:Array = ["time_2.swf", "time_3.swf", "time_4.swf", "time_5.swf"];

                            var myLoader:Loader = new Loader();

                            var myRequest:URLRequest;

                            var index:int=1;

                            var url:String = mySwfs[index];

                             

                                       

                            myBtn_next.addEventListener(MouseEvent.CLICK, nextBtnClick);

                            myBtn_back.addEventListener(MouseEvent.CLICK, backBtnClick);

                             

                             

                             

                             

                            function backBtnClick(event:MouseEvent):void

                            {

                                 loadSwf(--i);

                            }

                             

                             

                            function nextBtnClick(event:MouseEvent):void

                            {

                                 loadSwf(i++);

                            }

                             

                            function loadSwf(index:int):void

                            {

                                 url = mySwfs[index];

                                 myRequest = new URLRequest(url);

                                 myLoader.load (myRequest);

                                 myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,

                            loadProgress);

                                 myLoader.contentLoaderInfo.addEventListener(Event .COMPLETE,

                            loadComplete);

                                 checkButtons();

                            }

                             

                            function checkButtons():void

                            {

                                 

                                 if (i == mySwfs.length)

                                 {

                                      myBtn_next.gotoAndStop(2);

                                 }

                                 else

                                 {

                                      myBtn_next.gotoAndStop(1);

                                 }

                                 

                                 if(i > 0)

                                 {

                                      myBtn_back.gotoAndStop(1);

                                 }

                                 else

                                 {

                                      myBtn_back.gotoAndStop(2);

                                 }

                            }

                             

                             

                             

                            function loadProgress(evt:ProgressEvent):void

                            {

                                 var amountLoaded:Number = evt.bytesLoaded/evt.bytesTotal;

                                 amountLoaded = Math.round(amountLoaded * 100);

                            }

                             

                             

                            function loadComplete(evt:Event):void

                            {

                                 container.addChild(myLoader);

                            }

                            • 11. Re: How do I loadMovie in as3?
                              ASnewbie Level 1

                              As I said, the SimpleButton cannot have a gotoAndStop(2) or any gotoAndStop for that matter.

                              I saw this and Im once again certain these guys are buttons. Try to comment these and publish again.

                               

                               

                              function checkButtons():void

                              {

                               

                                   if (i == mySwfs.length)

                                   {

                                        myBtn_next.gotoAndStop(2);

                                   }

                                   else

                                   {

                                        myBtn_next.gotoAndStop(1);

                                   }

                               

                                   if(i > 0)

                                   {

                                        myBtn_back.gotoAndStop(1);

                                   }

                                   else

                                   {

                                        myBtn_back.gotoAndStop(2);

                                   }

                              }

                               

                              BR,

                              Murtuza

                              http://www.sowebme.com/murtaza

                              • 12. Re: How do I loadMovie in as3?
                                dustycoats Level 1

                                I took that chunk of code out:

                                 

                                now it says this:

                                 

                                1180: Call to a possibly undefined method checkButtons.  CheckButtons()

                                 

                                1120: Access of undefined property container. Container.addChild(myLoader)

                                 

                                When I take out the checkButtons(); from the code it gets rid of the 1180

                                error but I am not sure if I need that for something else.