MySpace/GetURL Solution: Not Perfect, But Stylish

Written by Bob de Wit. Posted in Developer Blog, Flash, Flex, PHP

Like most Flash developers, I was grinding my teeth when MySpace unilaterally decided to disable getURL() calls from Flash movies on their network. I was -and still am- convinced that the least MySpace could have done was to set up a program for Flash widget designers with good intentions in stead of hurling everyone back to the stone age (read: HTML links). Today I finished a new artist site for MySpace and I decided to dig a little deeper into the problem. But first, maybe for those not familiar with the origin of the problem, a little overview. Last year MySpace was attacked by a flash based worm. In response, MySpace has forced all flash movies to be played in version 9 of the Flash player. This version introduces several new network security features. The one relevant for the MySpace getURL issue is the parameters allowScriptAccess (already introduced in Flash player 6, but now enforced in version 9). MySpace disables links from flash including getURL by appending or overriding the following properties to your object tag:
  • # <param name=“allownetworking” value=“internal” /> # <param name=“allowScriptAccess” value=“never” /> # <param name=“enableJSURL” value=“false” /> # <param name=“enableHREF” value=“false” />
Possible values of allowNetworking are:
  • “all” (the default)–All networking APIs are permitted in the SWF.
  • “internal”–The SWF file may not call browser navigation or browser interaction APIs, listed later in this section, but it may call any other networking APIs. This one is enforced by MySpace.
  • “none”–The SWF file may not call browser navigation or browser interaction APIs, listed later in this section, and it cannot use any SWF-to-SWF communication APIs, also listed later.
Hence the getURL() problem. The command simply hits the security wall. Additional frustration is that the getURL() simply fails without any error being raised. Utterly frustrating. So what can be done? Well, several people apparently tried write the <embed> code in such a way that the MySpace parser would be “tricked” into not inserting the tags. And although some of these attempts had success, each of these parser gaps was quickly nerfed by MySpace. No long-term solution there. So let’s reverse the problem for a moment. In stead of focusing on what MySpace can block us from doing, what can MySpace NOT block without rendering all pages neolithic? Well, from that perspective, they can’t:
  • block Flash movies altogether. Bye galleries, music players, movie embedding? Don’t think so.
  • block Flash movies from accessing files in the same domain for the same apparent reason.
  • block basic HTML elements. <div>, <a> and <img> will always be there
Given this shortlist, some people looking for a more permanent solution have come up with overlaying a <div> containing a transparent gif on the Flash movie, thus enabling a link. While this approach works fine for simple flash sites, what to do for really dynamic Flash sites where things move, appear and disappear all the time? Could we make the overlaying link dynamic in some way? Yes we can, though it’s not perfect…but a Flash designer can certainly work it into his/her designs in such a way that it will look just like Flash. Take a look at my artist site – pop up the friends page, this will parse the friends list from MySpace and display this list in a Flash grid. Click on any of the icons, and you’ll see a link message appearing. Click on the link message and you’ll be taken to that profile. Come back, click another one in the friends list, click the link message again – you’re taken to the new profile you selected. How does this work? Well, there’s three components: obviously an overlaying <div>, and 2 simple scripts. I’ve used PHP, but you can easily duplicate this in any other language. Let’s start with the <div> part. Here’s the relevant code from my profile page:









Notice the transparent wmode parameter. And then we add an overlaying transparent GIF on top of the Flash movie:

As you can see, the transparent GIF links to a PHP script on my server called redirect.php. But how does the script know what to redirect to? Well, even if we can’t do direct linking from our Flash file, nothing stops us from passing the desired link to a script that stores it into a session variable. Since this session is tied to the browser, all the redirect script would need to do is pick up the session variable and redirect the user to whatever is stored in that variable. This implies passing the desired link from within your Flash movie to the redirect script. Here’s what happens in the Flash movie when you click on one of the friend icons in the list:
on (release)
{
    if (_root.MySpace == 1 )
    {
        wcap = "Click here to visit " + this.caption.text;
        _root.ByPassCaption = wcap.toUpperCase();
        _root.ByPassLink._visible = true;
        wurl = "http://mysite.com/myfolder/setlink.php?url=" +
          escape( "http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=" + this.id );
        LV = new LoadVars();
        LV.load( wurl );
    }
    else
    {
        getURL( "http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=" + this.id, "_blank" );
    }
}
The Flash script first determines wether is is running from a “normal” server or from MySpace. This can simply be done by passing a variable to the flash movie, like src=”movie.swf?MySpace=0?. For a normal server, it simply calls the getURL() script. In this way, you can use the same swf for your regular as well as for your MySpace site. When running from myspace, the script creates a LoadVars object and calls the script setlink.php, passing the url the user selected. The essence of the script is extremely simple:
    session_start();
    $url = $_REQUEST['url'];
    $_SESSION['url'] = $url;
It stores the passed url in the user’s session variable. Then all the redirect.php script does is pick up the url and jumps to it:
    session_start();
    $url = $_SESSION['url'];
    header("Location: $url");
And there you have it – a dynamic HTML link overlay thanks to user session variables. Only drawback is you need to click twice. As I said: not perfect, but at least I can use dynamic links again in Flash on MySpace.

Trackback from your site.

Comments (8)

  • Chris

    |

    Thanks for the blog.. Very good information. I’m wondering if you have any advice on passing a variable to flash within MySpace… such as embedding…. “thefile.swf?name=bob” MySpace seems to remove any variables in the querystring.

    Reply

  • Bob de Wit

    |

    There are several ways, depending on the type of parameters you want to pass:

    If the parameters are “fixed”, i.e. not dependent on visitor, time, etc:

    1. You can simply pass parameters to a flash movie by using the param tag within the flash object tag.

    2. You can make a urlencoded name pair text file and load it into Flash using LoadVars().

    If the parameters are dynamic:

    3. You can use the principle described in this article to pass parameters in stead of redirecting to a link. Just pass the parameters back in urlencoded name pairs to the Flash movie.

    Reply

  • music

    |

    very interesting.
    i’m adding in RSS Reader

    Reply

  • Doodee

    |

    Thanks for sharing

    Reply

  • hyearn

    |

    Gemstones

    Reply

  • likegluelikecrew

    |

    Maybe somebody here could help me. I’m not trying to do an elaborate MySpace site, but I am trying to do some Flash banners that people could embed into their myspace pages to promote my t shirt company. I want to have the swf banners link to my website. You said this could be done by overlaying a transparent gif and then linking it. Now, I’m a little coding challenged, could you walk me through exactly how to do that and what the code would look like to have someone embed it into their myspace page? I’ve searched the internet but haven’t come up with anything, any help would be awesome.

    Reply

    • Bob de Wit

      |

      This approach requires you to customize the relative position of the overlay depending on where your banners will be. Also, you need access to a web server where you can place the redirect.php. So I’m afraid I can’t give you a step-by-step walkthrough more detailed than what I posted.

      Reply

Leave a comment