17 Replies Latest reply on Sep 24, 2011 5:06 PM by kglad

    Passing parameters to an SWF

    ITango2

      I've somewhat decided n Anvsoft flv player for a flash website project.  There seem to be many of these players free and otherwise, but they seem to all publish for HTML, not from anothe SWF..

       

      The published html is below, and my question is how to call the SWF from Actionscript 2 rather than HTML?  I believe I can figure out the rest of the mechanics  thanks to a recent education .

       

       

      <body>
           <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="400" height="327">
               <param name="allowFullScreen" value="true"/>
               <param name="movie" value="videos.swf?xml_path=slides.xml" />
               <param name="quality" value="high" />
               <embed src="videos.swf?xml_path=slides.xml" width="400" height="327" quality="high" allowFullScreen="true" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>
           </object>
      </body>

       

      Thanks.

        • 1. Re: Passing parameters to an SWF
          kglad Adobe Community Professional & MVP

          you can load a swf using

           

          target_mc.loadMovie("yourswf.swf").

          • 2. Re: Passing parameters to an SWF
            ITango2 Level 1

            That part I understand, but I would think that the format of passing variables would be different from HTML to Actionscript?

             

            As always, thanks.

            • 3. Re: Passing parameters to an SWF
              kglad Adobe Community Professional & MVP

              you want to pass parameters to a swf from where?

              • 4. Re: Passing parameters to an SWF
                ITango2 Level 1

                Sorry, I should have assumed that info would be needed.

                 

                Movieclip button, onrelease, in an existing SWF website.  Called SWF to appear over existing SWF (popup).

                 

                Parameters to pass are sizing, xml data file, etc.

                 

                Basicly it's an aftermarket FLV player that has a bit more adjustment.

                 

                Soooo.... One swf calling another through actionscript 2 and passing configuration info.

                • 5. Re: Passing parameters to an SWF
                  kglad Adobe Community Professional & MVP

                   

                  Movieclip button, onrelease, in an existing SWF website.  Called SWF to appear over existing SWF (popup).

                  you're using getURL() to open the external swf's embedding html?


                  if yes, append a query string to the url with your data, use javascript in the embedding html to return the query string to your external swf using the flash externalinterface class.
                  • 6. Re: Passing parameters to an SWF
                    ITango2 Level 1

                    No.  I'd prefer to not use any HTML at all since the site is a flash web site.

                     

                    The above code was generated by this aftermarket FLV player that takes your FLV(s) and generates a playlist, skin, and vids into one SWF.  I posted the code to show what gets passed to the SWF when called.

                     

                    Of course how to pass in HTML and how to pass in AS 2.0 would be different syntax, and that's where my question is focused.

                     

                    So.  Existing Flash web site would on the click of a button (movieclip) call the other SWF passing it the same info as in the HTML above.

                     

                    I don't know that there is any reason to involve HTML at all is there?  Since we are dealing with two SWF files.

                    • 7. Re: Passing parameters to an SWF
                      kglad Adobe Community Professional & MVP

                      copy and paste the code you're using to "call" another swf that appears over your existing swf.

                      • 8. Re: Passing parameters to an SWF
                        ITango2 Level 1

                        I have none yet.

                         

                        I want to duplicate calling the other SWF and pass it configuration info via AS 2.  The above html code is how (and what) needs to pass to the receiving SWF IF DOING IT BY HTML, and was posted to show what the other SWF needs to receive.

                         

                        What I'm trying to determine is the syntax of how to pass information to an SWF in AS 2.

                         

                        I've searched the forums for passing parameters to SWF, but nothing came back with anything solid.

                        • 9. Re: Passing parameters to an SWF
                          kglad Adobe Community Professional & MVP

                          i wrote an article for the adobe knowledge base on as3 swf to as3 swf communication:  http://kb2.adobe.com/community/preview/918/cpsid_91887.html

                           

                          as2 to as2 swf, in this situation is the same as the last section of that article except you'll get getURL instead of navigateToURL(), if you're calling the embedding html.  if you're calling the swf directly, you can use the _url property of the main timeline to retrieve the url and query string.

                           

                          that article still needs some formatting help because it's been somewhat mangled by the publishing system, but that last section hasn't been badly mangled.

                          • 10. Re: Passing parameters to an SWF
                            ITango2 Level 1

                            Well, I'm getting a bit more confused as I go along ;-) 

                             

                            Is there a reason to have HTML involved at all if we are dealing with only an SWF calling an SWF?

                             

                            Or do I assume that the SWF being created by this software (Anvsoft Web FLV pro) has HTML receiving code built into it at creation time?

                            • 11. Re: Passing parameters to an SWF
                              kglad Adobe Community Professional & MVP

                              try calling the swf directly and see if the result is satisfactory.

                              • 12. Re: Passing parameters to an SWF
                                ITango2 Level 1

                                Well, that was surprising.

                                 

                                The generated html says to me that the receiving SWF would need input parameters, but other than defaulting to the upper left corner of the screen, it works.

                                 

                                I got that woked out by placing a transparent MC on the stage where I wanted it, and loaded to that.

                                 

                                The only thing lacking is a close button on the loaded SWF.  I'm thinking of using the same button to load and unload with a flag and if test?

                                 

                                Load code was easy..........

                                 

                                _root.page4.playvid_btn.onRelease=function() {

                                 

                                loadMovie("videos.swf",vidwin);

                                 

                                }

                                • 13. Re: Passing parameters to an SWF
                                  kglad Adobe Community Professional & MVP

                                  :

                                  .

                                   

                                  _root.page4.playvid_btn.onRelease=function() {

                                  if(vidwin._url.indexOf("videos.swf")==-1){

                                  vidwin.loadMovie("videos.swf");

                                  } else {

                                  vidwin.swapDepths(getNextHighestDepth());

                                  vidwin.removeMovieClip();

                                  }

                                   

                                  }

                                  1 person found this helpful
                                  • 14. Re: Passing parameters to an SWF
                                    ITango2 Level 1

                                    Thanks.  Very generous and I can re-use that.

                                     

                                    For my education, I'm going to look that stuff up (indexof) .  Everything else makes sense to me having worked with IF ELSE things before ;-)

                                     

                                    There seems to be one glitch though.  The button loads, and also unloads, but only once.

                                     

                                    Should I force the value going into the onRelease?

                                    • 15. Re: Passing parameters to an SWF
                                      kglad Adobe Community Professional & MVP

                                      if you want your button to trigger a load more than once, you should remove vidwin from the stage and use:

                                       

                                       

                                      .

                                       

                                      _root.page4.playvid_btn.onRelease=function() {

                                      if(!vidwin){

                                      createEmptyMovieClip("vidwin",getNextHighestDepth());

                                      vidwin._x =?

                                      vidwin._y = ?

                                      vidwin.loadMovie("videos.swf");

                                      } else {

                                      vidwin.removeMovieClip();

                                      }

                                       

                                      }

                                      1 person found this helpful
                                      • 16. Re: Passing parameters to an SWF
                                        ITango2 Level 1

                                        I've learned a lot in those two pieces of code.  You should write poetry

                                         

                                        If I'm understanding a few things correctly, the IF determines if vidwin is NOT there allready. Create a movie instance of  vidwin from the libraryand put it at the next available depth, and I guess that there are certain inherant functions to a movie clip including definable X and Y and of course loadmovie.

                                         

                                        It works perfectly, and I've learned alot .

                                         

                                        Best regards

                                        • 17. Re: Passing parameters to an SWF
                                          kglad Adobe Community Professional & MVP

                                          the if-statement checks if vidwin exists.  if not create an empty movieclip, not one from the library (which would be created using attachMovie() ).