0

OK, So I have a banner that will be place on a website and depending on the url I need to update the text in the swf banner. The text I need to grab will be something like this in the URL.

product="abc"

The "abc" could be different number of characters. I don't have the exact url to work with.

I got a partial answer over here: Get Current Browser URL - ActionScript 3

However this does not explain how I can specifically only get the name of the product.

Thanks You

Community
  • 1
  • 1

2 Answers2

0

You need a webservice or flashvars to know what the current product.

I hope this is helpful for you.

:)

  • Welcome to Stack Overflow, to make your answer actually helpful, consider adding an example. Otherwise it's not a very high quality answer and would be more appropriate as a comment (which I know you can't do yet). I'll gladly give you an up vote if you provide a decent example (since using FlashVars is a good way to accomplish this too). – BadFeelingAboutThis May 12 '15 at 16:41
0

You can do something like this:

//check to make sure you can use ExternalInterface
if(ExternalInterface.available){
    //grab the url from JavaScript
    var url:String = ExternalInterface.call("window.location.href.toString");
    //make sure the url is valid and has querystring parameters (eg a ?)
    if(url && url.length > 0 && url.indexOf("?") > -1){
        //split the url and grab everything after the ?, convert that into URL variable object
        var params:URLVariables = new URLVariables(url.split("?")[1]);
        trace(params.product); //abc
    }
}

For more info on getting the url properly, see the answer to this question

Community
  • 1
  • 1
BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40
  • Thanks for the answer. I don't understand one thing in the code. 'trace(params.product);' Instead of this line I am using 'myText.text = params.product;' also I tried using myText.text = url; even this did not work. – user3676944 May 13 '15 at 17:02
  • trace just puts whatever you pass into the flash output window. It's the equivalent of console.log in javascript. What I'm trying to convey, is you access your value by doing `params.product`. Are you saying `myText.text = params.product` is not working? – BadFeelingAboutThis May 13 '15 at 17:05
  • Yes It's not working. I uploded my file to a server to check but the textbox remains empty. What i don't understand is where did the ".product" come from. This was never defined or created. – user3676944 May 13 '15 at 17:10
  • it's a dynamic object created by the `URLVariables` class when you pass it a url variables string. But it's likely your not getting that far, probably the `url` var is not populating for some reason. If you do: `myText.text = ExternalInterface.call("window.location.href.toString")`, what is the result? (make sure to put that code NOT in the inner if statement) – BadFeelingAboutThis May 13 '15 at 17:17
  • I get TypeError: Error #2007: Parameter text must be non-null. at flash.text::TextField/set text() at draft_fla::Layer1_3/frame1() in the output window and nothing on the server. – user3676944 May 13 '15 at 17:23
  • Ok, your either running in a browser where that javascript doesn't work, or are missing required tags/ids for it to work. Look at the answer to this question: http://stackoverflow.com/questions/1478015/getting-current-url-in-flash-from-javascript-using-externalinterface-and-ie – BadFeelingAboutThis May 13 '15 at 17:27
  • You are right. I got this 'myText.text = ExternalInterface.call("window.location.href.toString")' to work in firefox. but 'myText.text = params.product' is still not workink. – user3676944 May 13 '15 at 17:53
  • Can you paste the url that you get from window.location.href.toString? feel free to change the domain for privacy – BadFeelingAboutThis May 13 '15 at 18:01
  • Thanks Man, This worked perfectly fine. Just had to change the word product to the variable in the URL. Stupid me. Thanks again for your help. – user3676944 May 14 '15 at 03:08
  • Sorry to bother you again, Is there a way to make it work offline on desktop instead of a server, it works perfectly fine on the server. I would like to be able to work locally as well. – user3676944 May 14 '15 at 06:51
  • What do you mean by offline? It will run the same in a browser be it online or offline. If you are running it as an .exe, then there is no url to be had so you'd have to pass in parameters another way (loading in a text file etc) – BadFeelingAboutThis May 14 '15 at 15:58
  • Nevermind, I used a text file as you mentioned. Thanks a ton for you help. – user3676944 May 16 '15 at 12:07