MySpace/GetURL Solution: Not Perfect, But Stylish

Written by Bob de Wit. Posted in Developer Blog, Flash, 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: <object enableJSURL=”false” enablehref=”false” saveEmbedTags=”true” allowScriptAccess=”never”         allownetworking=”internal” type=”application/x-shockwave-flash” allowScriptAccess=”never” allownetworking=”internal” height=”750″ width=”768″ data=”http://sites.sitelinx.net/carbonbass/cb2008.swf”> <param name=”allowScriptAccess” value=”never” /> <param name=”allowNetworking” value=”internal” /> <param name=”movie” value=”http://sites.sitelinx.net/carbonbass/cb2008.swf” /> <param name=”quality” value=”high” /> <param name=”scale” value=”noscale” /> <param name=”bgcolor” value=”#000000″ /> <param name=”wmode” value=”transparent” /> </object> Notice the transparent wmode parameter. And then we add an overlaying transparent GIF on top of the Flash movie: <div style=”width: 350px; position: relative; top: -70px; left: -70px;”> <a href=”http://sites.sitelinx.net/carbonbass/redirect.php”> <img src=”http://x.myspace.com/images/clear.gif” border=”0″ width=”350″ height=”20″> </a> </div> 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://sites.sitelinx.net/carbonbass/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: <?php
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: <?php
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 (18)

  • michelle

    |

    You are too amazing! Would you consider helping a novice with big dreams? If your time permits could you help me put a flash banner on top of myspace like this: http://myspace.com/MarilynManson
    I can get the space for the banner but I’m so sure how to work the rest of the css to trick myspace with the transparent gif stuff. Could I put it in the
    reBannerUpper section?

    body.bodyContent{background-color: E5E5E5;background-position: top center;background-repeat: repeat-y;background-attachment: fixed;margin-top: 181px;}body.bodyContent{background-color: 000000;}.

    reBannerUpper{height: 181px;rc: 1;position: absolute;rc: 1;width: 850px;rc: 1;margin-left: -425px;rc: 1;left: 50%;rc: 1;top: 0px;}

    Reply

  • Bob de Wit

    |

    If I were you would just the gif over the flash area like I did using a negative offset iso trying to css, seems easier to me. What is your MySpace page?

    Reply

  • Joe

    |

    Hey I want to do this for my myspace but am having trouble. Not really sure what you did. I tried following along but cant figure it out. If you could help me I’d really appreciate it. You can just email me at porschefb61@gmail.com . Thanks.

    If you need the actual flash file or any information let me know.

    Reply

  • mecopius

    |

    YOU ARE PURE GENIOUS!!!!!!!!!!!!! I LOVE IT!!!!!!!!!!!!!!!!!

    Reply

  • SlickG

    |

    Is there any way where you can link the code directly from the Flash Layer instead of establishing another link under the Flash? Take an example from the myspace that I’m creating, http://myspace.com/americanhypetravel .Is ther any way I can have the link normal as if the Geturl option was really working? Please drop me an email, cortech@cortechx.com

    Thanx ;)

    Reply

  • johnny

    |

    not sure what im doing wrong but it still links to your site even after i changed the web address please help

    Reply

  • neil

    |

    hi all, the only problem with this is if you have a links section on a widget or interactive banner which isnt visible on the first instance of the flash movie, you’ll have invisible links throughout the other sections/instances, anyone have any ideas? if your baffled by what i mean, i designed a small widget / interactive banner for these guys: http://www.myspace.com/officialaddictive

    if you go to the links section youll see what i mean.

    thanks.

    Reply

  • Daniel

    |

    Your solution works great. I am just having trouble moving the transparent gif where I need it to be over my .swf file. In other words I need it to be over the image that I want linked. Any suggestions?

    Daniel

    Reply

  • GR27

    |

    Thank You! We needed this without the dynamic part SO BADLY! Took a bit of finesse to get the floating gifs to line up, and a bit of absolute placement but it worked. :) :) :) :) :)

    Reply

  • Christian

    |

    We are hoping to implement this with our information network. We have PyraWords that is a competitor to Google adwords. You can post your information to the network for one penny and as it virally travels you can actually make money and it gets more circulation. Users of the PyraWords get $5 if someone else joins the network. This will be huge if we can implement this one myspace.

    Reply

  • Randy

    |

    I don’t think this works any longer. I can get it to work fine on all pages but myspace.

    Reply

  • Randy

    |

    by the way, how did you get your redirect.php link to not show up as a msplinks.com link?

    Reply

  • Flüge

    |

    Yes great problem solving skills you showed there. I like the well structured, sophisticated and analytic way you use to elaborate the problem and serve the solution. Great work, dude!

    Reply

  • Steven de la Torre

    |

    this is a very clever solution – does it still work?

    Reply

  • adam

    |

    Nice work!!!

    Reply

  • piotr

    |

    Yeah… it kinda worked, but no longer – myspace parses everything since last two or so weeks and we cannot get around that — any clues appreciated…

    Reply

Leave a comment