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?
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.
More new things…
This week I started working on a new Flash/Flex based application that allows users to create a playlist, upload songs, put the songs in a playlist, and then be able to embed the Music Player on their blog/myspace/website etc…
http://www.mymusicplayer.ericschleeper.com/
This is actually three swf’s that connect to the same AMFPHP gateway. One is a fairly secure login/account create page, one is the admin page, and the last is the actual player.
To see more and download some of the source code, keep reading
New things…
I’ve been busy with some things for Goose Dog Designs. We are excited about the next launch of Cerqua Rivera Dance Theatre’s new site. They were very happy with what we gave them at the end of 2008 that they wanted some more features and content. My new app uses MVC design. A sneak peak can be seen here:
http://www.cerquarivera.org/revamp
Also, I created a music mashup site that uses the MTV content API, the lyrics fly API, and Amazon Web Associates API. I got some design help from a friend and we are happy with what we made. I am using Wordpress for about 50% of the backend. However I am completely overriding the admin page and creating posts from Flash. Unfortunately, I just found out that MTV decided to remove the part of their API that returns the embed code for the video. A few weeks ago I noticed that it wasn’t working right, then it was working right again. So I don’t know what the future of this site will be..
Also, I have been doing some spec work for a photographer. I created a php site with an admin page that uses flex. The page is fairly simple:
http://www.ericschleeper.com/visexpressdev/
but my admin page uses Flex with remoting to php and it even looks up maps on Google Maps API.
http://www.ericschleeper.com/visexpressdev/admin.html
To work on my design skills I made a “fake” gourmet food store:
code.ericschleeper.com
I created this page as a place to store a template for my Flash Projects. I have been using Model View Controller and I have quickly found that I am writing a lot of the same things over. Whenever i start a new project I begin by opening up old ones and stripping things out and changing things around and looking in the nerd bible to remember how/why I did something a certain way. Instead, I now have a zipped file in the subdomain that is a great starting point for a Flash app. I made these available for anyone and I have some explanation on how they work and how to implement them. My latest experiment involves putting a factory on a composite view. I have been doing this a lot on this project I have been wokring on and found it to be very effective. I plan on adding some more, like a basic MVC app that connects to an AMFPHP gateway. Please take a look:




