7 Replies Latest reply on Nov 2, 2006 6:19 AM by TimSymons

    get url from SWF

    cadflash2
      I'm calling the same swf file from different aspx page. Based on the aspx file name, I need to do some code change on the action script. How can I get the aspx file name from which the swf is called? I tried the _URL which gives the location of the SWF file.
        • 1. Re: get url from SWF
          TimSymons Level 1
          Not sure if there is already something in Flash that you could use but the first thing I thought of was to just pass the "document.location" JavaScript property (or whatever the equivalent is in .NET) with the call to the Flash file. To do this just tack on the information like you would to any other HTML URL request.

          flashfile.swf?varibleInFlash=location

          In your Flash file, on Frame 1. Initialize your variable with something like:

          var variableInFlash:String;

          Then once your movie is loaded that variable will contain whatever value you assigned to location.

          Tim
          • 2. Re: get url from SWF
            cadflash2 Level 1
            Is there any way to call the javascript from the flash to get the document location. Because our web pages are automatically generated, so it's difficult to pass any variable to the flash file.
            • 3. Re: get url from SWF
              TimSymons Level 1
              Yes. Look into the ExternalInterface class in Flash 8. The help files will explain it better than I can but you can definitely do it that way.

              Tim
              • 4. Re: get url from SWF
                cadflash2 Level 1
                I tried the sample which is given in the ExternalInterface.call to call javascript method which will give a string value. I tried exact code as given in the help. The alert box is showing. But the retun text is getting as null. Looks like this method is not working. So I may have to go back and pass the windows.location as parameter. Can somebody please tell me how to do that since I'm not that expert in javascript?
                • 5. Re: get url from SWF
                  TimSymons Level 1
                  You know, I not sure what I was thinking when I sent that last post. Since you said that your pages are generated automatically the ExternalInterface class wasn't going to work for you either because their is no JavaScript function for you to call to first.

                  Can you modify how your web pages are generated?

                  Tim
                  • 6. Re: get url from SWF
                    cadflash2 Level 1
                    I can not modify the way of generation. But flash piece is in ascx, automatic generation is grabbing the html content of this and updating the actual aspx page. That means in my case, suggestion in the first reply will be the solution.
                    flashfile.swf?varibleInFlash=location
                    But I need to get this 'location' from javascript. How can I do that?
                    • 7. Re: get url from SWF
                      TimSymons Level 1
                      Oh, sorry I misunderstood. To get your current location from JavaScript use the following line of code:

                      var myLocation = document.location;

                      This will place the current (full) URL in the variable myLocation. If you want to just get the very last item of the URL then you could use something like this:

                      var myLocation_array = document.location.split("/");
                      var myLocation = myLocation_array.pop();

                      Then the variable myLocation will only contain the name of the page loaded and not the entire " http://www.url.com/....." stuff.

                      Tim