21 Replies Latest reply on Oct 2, 2009 9:50 PM by dustycoats

    Need all my swfs to load in one html file but this code does not work

    dustycoats Level 1

      Hello, thanks for looking,

       

      II found this code to load a movie but naming the button myRequest or myLoader  does not do anything????/

       

       

       

       

       

       

      //loadMovie\\

       


            var myLoader:Loader = new Loader();
       
            var myRequest:URLRequest = new URLRequest("story_2.swf")
        
            myLoader.load (myRequest);
       
            

            myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
        
            myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
       
            
        
      function loadProgress(evt:ProgressEvent):void {
      var amountLoaded:Number = evt.bytesLoaded/evt.bytesTotal;
       
      amountLoaded = Math.round(amountLoaded * 100);

      }

      function loadComplete(evt:Event):void {

       

            }

        • 1. Re: Need all my swfs to load in one html file but this code does not work
          __antonio__ Level 3

          This code does not reference any button. Do you have a button on stage? what do you want that button to do?

          • 2. Re: Need all my swfs to load in one html file but this code does not work
            dustycoats Level 1

            HUh? well that would explain it.  I am trying to do what used to be called a loadmovie.  I have many swfs in a folder but want them to load in one "master" html so the don't keep opening in many windows

            • 3. Re: Need all my swfs to load in one html file but this code does not work
              __antonio__ Level 3

              You still need to add myLoader to the stage or another container clip.

              var myLoader:Loader = new Loader();
              var myRequest:URLRequest = new URLRequest("story_2.swf")
              myLoader.load (myRequest);
              
              myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
              myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
                
              function loadProgress(evt:ProgressEvent):void
              {
              var amountLoaded:Number = evt.bytesLoaded/evt.bytesTotal;
              amountLoaded = Math.round(amountLoaded * 100); 
              }
               
               function loadComplete(evt:Event):void
              {
                   this.addChild(myLoader);
              }
              
              • 4. Re: Need all my swfs to load in one html file but this code does not work
                dustycoats Level 1

                I changed my button name to myLoader and got this

                 

                 

                 

                1151: A conflict exists with definition myLoader in namespace internal.

                • 5. Re: Need all my swfs to load in one html file but this code does not work
                  dustycoats Level 1

                  ooops, here is the code:

                   

                  stop();

                   

                  import flash.events.MouseEvent;

                   



                  var myLoader:Loader = new Loader();
                  var myRequest:URLRequest = new URLRequest(story_2.swf)
                  myLoader.load (myRequest);

                   

                  myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
                  myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
                   
                  function loadProgress(evt:ProgressEvent):void
                  {
                  var amountLoaded:Number = evt.bytesLoaded/evt.bytesTotal;
                  amountLoaded = Math.round(amountLoaded * 100);
                  }

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

                  • 6. Re: Need all my swfs to load in one html file but this code does not work
                    __antonio__ Level 3

                    You are getting the error on your button because myLoader is a Loader instance not your button.

                     

                    If you have a button on stage try renaming your button instance name to myBtn, then:

                     

                     

                    stop();

                     

                    import flash.events.MouseEvent;

                     



                    var myLoader:Loader = new Loader();
                    var myRequest:URLRequest = new URLRequest(story_2.swf)
                    myLoader.load (myRequest);

                     

                    myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
                    myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
                     
                    function loadProgress(evt:ProgressEvent):void
                    {
                    var amountLoaded:Number = evt.bytesLoaded/evt.bytesTotal;
                    amountLoaded = Math.round(amountLoaded * 100);
                    }

                    function loadComplete(evt:Event):void
                    {
                      myBtn.addEventListener(MouseEvent.CLICK, addSwf);  
                    }

                     

                    function addSwf(event:MouseEvent):void

                    {

                      this.addChild(myLoader);

                    }

                     

                     

                     

                     

                     

                    This is really quick, based off of what code you already have. I would really just write it differently.

                    • 7. Re: Need all my swfs to load in one html file but this code does not work
                      dustycoats Level 1

                      Thanks so much for all the time on this:

                       

                      Are you saying there is a better way?  What would that be and why would it be better?  I have a ton of online modules I will be building in as3 and am new to it but want to use as3 so i won't be building out dated material.  As2 was easy to use the old loadmovie: One folder with one html file and my swfs.

                      • 8. Re: Need all my swfs to load in one html file but this code does not work
                        dustycoats Level 1

                        I tried the code and changed the button name to mybtn and got this error

                         

                        1120: Access of undefined property story_2.

                        • 9. Re: Need all my swfs to load in one html file but this code does not work
                          __antonio__ Level 3

                          Sorry, I didnt notice before that story_2.swf in your URLRequest needs to be in quotations: "story_2.swf"

                           

                           

                          Doing it the way you have been and with the code i provided was only to get you started in the right direction. How you build the rest is up to you. The first thing i would change is to put the loaded swfs into a container mc so I could replace them as needed and have things overlay. Doing it the way above puts the swf at the top, above your buttons and all other on stage graphics.

                           

                          Consider this:

                          Create an empty mc, place it on stage at 0,0, give it an instance name of container

                           

                          then:

                           

                          stop();
                          
                          import flash.events.MouseEvent;
                          
                          var myLoader:Loader = new Loader();
                          var myRequest:URLRequest = new URLRequest("story_2.swf");
                          myLoader.load (myRequest);
                          
                          myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
                          myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
                           
                          function loadProgress(evt:ProgressEvent):void
                          {
                          var amountLoaded:Number = evt.bytesLoaded/evt.bytesTotal;
                          amountLoaded = Math.round(amountLoaded * 100);
                          }
                          
                          function loadComplete(evt:Event):void
                          {
                            myBtn.addEventListener(MouseEvent.CLICK, addSwf);  
                          }
                          
                          
                          function addSwf(event:MouseEvent):void
                          {
                            container.addChild(myLoader);
                          }
                          
                          • 10. Re: Need all my swfs to load in one html file but this code does not work
                            dustycoats Level 1

                            HI Antonio,

                             

                             

                            I tried this much to no avail.

                             

                            I created a new symbol, selected movie for the behavior and named it mc.  I

                            then added it to the stage at: 0,0,  and then named the instance of it

                            container.  I only see it load on top of th old swf and need it to replace

                            like a slide show. I used to use the loadmovie in AS2.

                             

                             

                            Also I have a sort of "rewind" and fastforward" button setup that needs to

                            navigate from slide to slide what would the code look like with a rewind

                            btn, a fastforward button and a home button??/ thanks for your time on this.

                             

                            The error I get is

                             

                            1046: Type was not found or was not a compile-time constant: container.

                             

                            But it is in there...

                             

                             

                            Here is the code you sent and the file is attached

                             

                             

                             

                             

                            stop();

                             

                            import flash.events.MouseEvent;

                             

                            var myLoader:Loader = new Loader();

                            var myRequest:URLRequest = new URLRequest("story_2.swf");

                            myLoader.load (myRequest);

                             

                            myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,

                            loadProgress);

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

                             

                            function loadProgress(evt:ProgressEvent):void

                            {

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

                            amountLoaded = Math.round(amountLoaded * 100);

                            }

                             

                            function loadComplete(evt:Event):void

                            {

                              myBtn.addEventListener(MouseEvent.CLICK, addSwf); 

                            }

                             

                             

                            function addSwf(event:MouseEvent):void

                            {

                              container.addChild(myLoader);

                            }

                            • 11. Re: Need all my swfs to load in one html file but this code does not work
                              __antonio__ Level 3

                              dusty,

                               

                              You seem to be getting ahead of yourself with the rewind, fastforward buttons. Have you gotten just the one swf to load first?

                               

                              I've attached a zip with just linking to story_2.swf, with some cleaned up code.

                              • 12. Re: Need all my swfs to load in one html file but this code does not work
                                dustycoats Level 1

                                You're right, I could be getting ahead of myself.  I got this code to work,

                                sort of.  It loads the new .swf but I need it to remove the old one as I see

                                both after clicking on the button!

                                 

                                I am setting up a module and may have about 20 sfws.  When I say a fast

                                forward button  I really mean "advance to the next slide."  And when I say

                                rewind I mean "go to previous slide."  Would it be better to load them on

                                top of each other so that when the students go through the module they can

                                return to a slide quickly or should they replace each other?  Nonetheless, I

                                tried copying bits of the code you sent to create a "go to previous slide

                                button" and a home button but that was really getting ahead of myself.

                                Thanks Antonio for the time you have given me already and in advnce for any

                                more you may share.  Aloha,  Chris

                                • 13. Re: Need all my swfs to load in one html file but this code does not work
                                  __antonio__ Level 3

                                  You're welcome.

                                   

                                  Now that you have the one working, it'll be easier to understand how to get the rest going. It's usually best to remove the previous child before adding a new one, this way you don't have 20+ swfs on top of each other. To remove the previous one, just use removeChild(); in your button's eventListener function right before calling addChild.

                                   

                                  To load in so many, I would suggest looking into loading an xml doc that contains the swfs' paths, itll be easier to add to and subtract from. Your next and back buttons can just step through the xml nodes.

                                   

                                  Here's a good tutorial on xml in as3 to start you in the right direction:

                                  http://www.kirupa.com/developer/flashcs3/using_xml_as3_pg1.htm

                                  • 14. Re: Need all my swfs to load in one html file but this code does not work
                                    dustycoats Level 1

                                    Thanks again, that looks daunting.  Any way you can provide me with a code

                                    to load/remove and go forward and backward for now?  I put these up in our

                                    moodle server and they run great for my editing class.  I used to build this

                                    as2 with the loadmovie and never had a problem but this as3 is killing my

                                    love for flash,  Thanks again, Chris

                                    • 15. Re: Need all my swfs to load in one html file but this code does not work
                                      __antonio__ Level 3

                                      I may not be getting to a computer with the proper programs for a while today, so I wont be able to post code or anything for a bit.

                                       

                                      Don't be affraid of AS3. There may seem to be more lines of code to write but really it is much more straight forward and linear (first do this, then do this, then... etc.). Keep in mind that even though AS3 is a version of ActionScript, AS2 and AS3 are hardly comparable. Code can be translated, but they are different enough to be thought of as different, not a next evolution of. Once you realize this AS3 will make perfect sense and can be quite enjoyable. I used to HATE AS2, just couldn't get the hang of it. But once I switched to using AS3 I've been having WAY much more fun with it.

                                      • 16. Re: Need all my swfs to load in one html file but this code does not work
                                        dustycoats Level 1

                                        I took a class with Rich Schupe this summer and he said the same so I know

                                        it is true.  I guess I don't know when it will get fun.  I am trying to keep

                                        up with an eager film class and love posting my modules online so they

                                        absorb more but the navigation thing has slowed me down.  I have been using

                                        a get URL but they all open in new windows.  It works for getting the

                                        material delivered but looks unprofessional, yet I feel the need to create

                                        all new material in as3 so it can update, if needed, easier down the road.

                                        No prob on getting to the computer but when you can that would be so helpful

                                        to me and some budding film students, thanks again for working with me.

                                         

                                        P.S. I have another .fla file I would love to complete to teach editing.

                                        Rich got me going on it. It is basically a user defined array where the

                                        students could rearrange clips from a scene (the array are clips) and then

                                        play it back to see the difference in how the order of the clips can make a

                                        big difference such as: a girl frowning to a clip of a gun to a girl smiling

                                        (to use an old Russian editors' example).  Are you interested in taking a

                                        look at that some day?  Rich got the clips working where the user can

                                        rearrange them but did create the playback part of it.  Thanks a million

                                        • 17. Re: Need all my swfs to load in one html file but this code does not work
                                          dustycoats Level 1

                                          HI Antonio, just wanted to see if you had a chance to look at the load and

                                          remove swf from an html doc.  If not that's cool but was just wondering,

                                          Aloha, Chris

                                          • 18. Re: Need all my swfs to load in one html file but this code does not work
                                            __antonio__ Level 3

                                            Ok so this isnt perfect, but here is a version with next/back buttons.

                                             

                                            So basically I have myBtn_back and myBtn_next, and since you said you were comfortable with arrays in AS2, I made the buttons step back and forward through an array. they kinda bug a little when you are on the first and last of the array or if you toggle between pressing either while on one swf.

                                             

                                            I did this kinda quick tonight (well, quick to me), so it might be a little sloppy and probably not up to a real devs par. But here's the code:

                                             

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

                                             

                                            (P.S. I'm kinda in the same boat you are, learning this as I go. Really, I'm a Designer by day and Developer by night - sorta)

                                            • 19. Re: Need all my swfs to load in one html file but this code does not work
                                              __antonio__ Level 3

                                              Side note: You would think Adobe would have a decent syntax highlighter for AS3.

                                              • 20. Re: Need all my swfs to load in one html file but this code does not work
                                                dustycoats Level 1

                                                Thanks so much Antonio, will check this out later this week when I can come

                                                up for air....

                                                • 21. Re: Need all my swfs to load in one html file but this code does not work
                                                  dustycoats Level 1

                                                  HI Antonio

                                                   

                                                  I tried this week a go and got several compiling errors so had to resort back to the get URL and hope the kids did not get too bothered by everything opening in a new window.  Did you ever have a chance to go back and look at this?

                                                   

                                                  I still can't believe as2 to as3 is so different I can't get what used to be a simple load.movie code together for these online modules.  Thanks again for taking a look at this, again I just need about 20 different .swfs to load into one HTML doc.

                                                   

                                                  Should I be setting these up using a GoToandPlay?  The thing is i am using some of the quiz components and they dont work with AS3

                                                   

                                                  Thanks, Chris

                                                   


                                                  On 9/14/09 9:36 PM, "__antonio__" <forums@adobe.com> wrote:

                                                   

                                                  > Ok so this isnt perfect, but here is a version with next/back buttons.

                                                  > So basically I have myBtn_back and myBtn_next, and since you said you were
                                                  > comfortable with arrays in AS2, I made the buttons step back and forward
                                                  > through an array. they kinda bug a little when you are on the first and last
                                                  > of the array or if you toggle between pressing either while on one swf.

                                                  > I did this kinda quick tonight (well, quick to me), so it might be a little
                                                  > sloppy and probably not up to a real devs par. But here's the code:

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

                                                  > (P.S. I'm kinda in the same boat you are, learning this as I go. Really, I'm a
                                                  > Designer by day and Developer by night - sorta)
                                                  >
                                                  > --------------------------------------------------------------
                                                  > This message was sent to: dustycoats
                                                  >
                                                  > To post a reply to the thread message, either reply to this email or visit the
                                                  > message page:
                                                  > http://forums.adobe.com/message/2249337#2249337
                                                  >

                                                  >
                                                  > --end--