Getting the domain name of the page displaying the swf

I was recently involved with a project that required tracking links from a Flash widget marketing campaign. The problem is, that Flash player does not send the referer in the header or allow the referer to be set programatically. So the solution is to set up a campaign that includes the referer as a GET string in the url. So, how do you get the domain name of the page that the Flash is embedded on? Well a good way is to use the ExternalInterface class. Like this:


referer = ExternalInterface.call('eval', 'window.location.hostname');

Then you just concat the referer var onto the end of your URLrequests. Simple right? Not quite. See, the client was encouraging their associates to put the widget onto social networking sites and personal blogs. Well apparently many of these sites strip out the allowScriptAccess=’always’ param of the embed/object tags. So Flash Player would pop up a screen that says:

ActionScript Security Error 2060: Security sandbox violation: ExternalInterface caller http://www.whateverdomain.com/whatever.swf
cannot access

http://www.whateverotherdomain.com/

So, what’s the fix?

Continue reading

Working with the Flex consumer class and datagrids

I was recently working on a Flex app that showed delayed stock quotes and charts. The client was using Blaze DS on the backend. It is one of the best ways to hook Flash/Flex to a data source and absolutely perfect for this project. We were using the consumer class in Flex and once the subscribe method was called, new poll results were coming in every second. The poll results were in the form of an array collection and were displayed in multiple datagrids nested inside containers behind a TabNavigator and others in an Accordion.

I pulled these controls into seperate components and used binding to get the data to “trickle” down into the controls. The Accordion had four different panes, each with a datagrid, and each had a different filter for the data. Easy, assign a filter function and call the refresh function on the accordion change event.

The problem that we ran into was that we were losing our selected item in the datagrid every time new poll results came in. What I found to be the best solution: Create a variable that holds the value of the selected index of the datagrid. Assign it when the change event is triggered. Then create a setter for the array collection and assign the selected index of the datagrid to the value of the variable that holds your selectedIndex.

Click through to see the code.

Continue reading

Simple Observer Pattern in Actionscript 3

I was just posting on a forum on kirupa.com that started with someone asking about how to listen for a variable to change values. I thought about how this is a key part of the MVC design so I wrote a couple classes and posted them. After I did this I realized that it was most likely a good example of the observer pattern and after consulting my newest nerd bible I realized that I had it down, except for implementing the interfaces.

Click Here to See the Thread on kirupa.com

Anyways I thought I would post these classes here.

Continue reading

Singleton Pattern Actionscript Music Player

A designer I do some work for hired me to make a Music Player for a Flash web page. The requirements were to have the page start playing a song from frame 1 of the time line while an intro animation was playing. After the animation, there would be a button that allowed the user to play and pause a song. I chose to use the Singleton Design Pattern because frame one of the time line could create the instance, then a MovieClip Symbol could get the same instance later and call its functions without anything strange occurring (like the song playing again, while the first song played, also). The code is in the rest of the entry.

Continue reading