Question

I am using SWFAddress in actionscript 3 to control urls for navigation and controls, and while I am able to target and change specific parameters, I feel like I am missing a cleaner and more consistent way of handling it, perhaps even a feature or method I am not aware of.

Say I have a url and I want to change just the second param of def to xyz.

http://localhost/some-page/#/?param1=abc&param2=def&param3=ghi changed to http://localhost/some-page/#/?param1=abc&param2=xyz&param3=ghi

I currently am doing:

if (SWFAddress.getParameterNames().indexOf("param2") >= 0) {
    SWFAddress.setValue(SWFAddress.getPath() + "?"
       + SWFAddress.getQueryString().replace("param2=" + SWFAddress.getParameter("param2"), "param2=xyz"))

Essentially, checking if the param exists, checking what its current value is, then recreating the whole url using base, '?", and query, making sure I replace the the parameter and the parameter's value, making sure I don't miss the equal sign. This get's sloppy, and is error prone if the param exists but is not set to anything, or whether or not there is an equal sign, and a host of other pitfalls.

So, I can not just tell SWFAddress to update that one parameter in the url? A theoretical function of SWFAddress.setParam("param2, "xyz").

Has anyone coded their own method to micro-manipulate SWFAddress and the url, beyond the single function they supply you with of setValue(val:String)?

Was it helpful?

Solution

I think the short answer is no. According to the documentation there is no setParameter to go with the getParameter method. Looking at the code, it seems that the URL is not cached as a property in the class and therefore cannot be manipulated other than via the setValue method which, of course, updates the URL in the browser.

Presumably you're already parsing the URL in your onChange event so you can use the values to set your application state? If so, you shouldn't need to do so again when you come to rebuild the URL prior to updating it from Flash. If you store the deep-link properties on a Model class somewhere you can handle the defaulting, updating, and error checking without needing to resort to String manipulation. You would then rebuild the URL using those properties, a process you could abstract into a method in your Model class if required.

You should also note that the following line is not particularly robust since it will return true for properties such as param22 and sparam2:

if (SWFAddress.getParameterNames().indexOf("param2") >= 0) { }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top