Behavior, Content, Money – 3 Things you should never give away for free!!!

BCmoney MobileTV

From Flash to JavaScript and back AGAIN

Posted by bcmoney on June 9, 2010 in AJAX, Flash, HTML, JavaScript with 1 Comment


No Gravatar
Nederlands: Afbeelding van lagen in Flash CS4 ...

Image via Wikipedia

Inspired by several tutorials I did back in University, I decided to update a little script to pass data in between Flash and AJAX using only pure JavaScript and ActionScript to talk to one another.

In fact, this was arguably even easier back in ActionScript 2.0, where you could simply reference JavaScript variables directly. Now, there is a slightly more complicated API, but before we get ahead of ourselves, let’s list all possible options…

Flash to AJAX

  1. FABridge – Flex to Ajax Bridge (requires code from Adobe)
  2. HTTP request to server-side intermediary (not the most efficient)
  3. Flash Cookies (hard to handle/delete properly)

AJAX to Flash

  1. Flashvars + URL Parameters (good-old fashioned Flashvars never fail)
  2. Remote Scripting (not the most secure)
  3. Cookies (not too reliable)

As mentioned, just the act of making an HTTP request to load a URL got slightly more complex from AS2 to AS3.

In ActionScript 2.0 we had:

getURL(“http://domain.com/webpage.html”,”_blank”);

In ActionScript 3.0, for better or worse we now have:

my_btn.addEventListener(MouseEvent.CLICK, getURL);

function getURL(event:MouseEvent):void {
var url:URLRequest = new URLRequest("http://www.domain.com/webpage.html");
navigateToURL(url, "_self");
}

Above, I’ve linked to examples from which I drew the inspiration (ahem… borrowed some initial code) for this exercise. There are two classic posts from the Flash developer community that provided my very first use-cases and ways to implement this Flash-to-JS communication though. The first is Flash Interactive with JavaScript by F. Permadi, and the second is Passing Variables Around from HTML to Flash, where Jesse Stratford demonstrated indirect interactivity between JavaScript and ActionScript that I had thought impossible prior to reading it, passing all values via URL rather than relying on internal and constantly changing Flash APIs. Once you could bridge the web into Flash though, it opened up a world of possibilities, and suddenly the Macromedia framework became more than just a cool little tool for hobbyist web animators, game designers and geeks. Totally customizable and interactive SWF movies were possible, for example, Jeroen Wijering’s JW Media Player and countless other amazing Flash components.

In honor of the original works, I’m releasing an update for how to bridge flash to JavaScript using a combination of the methods prescribed above for going from AJAX to Flash and back again. I’ll start with simple URL-based value passing and as time permits will add Flex Ajax Bridge and Cookies, so be sure to check back later:


-or-

 

UPDATE: (2011-12-17) Now, in the latest version of Flash we also have the newer Flex 4.0 approaches such as Flex iFrame, as users seem to be embracing Adobe’s attempts to merge its Flash suite and FlexBuilder IDE with the open source release of FlashBuilder and more HTML5.

 

 

  1. ValCousinsAugust 31, 2013 - 11:29 am #1

    Greetings, nice information and tidy blog you’ve got here. Thanks for the info!

    Reply
Leave a Reply

No trackbacks yet.

No post with similar tags yet.

Posts in similar categories

BC$ = Behavior, Content, Money

The goal of the BC$ project is to raise awareness and make changes with respect to the three pillars of information freedom - Behavior (pursuit of interests and passions), Content (sharing/exchanging ideas in various formats), Money (fairness and accessibility) - bringing to light the fact that:

1. We regularly hand over our browser histories, search histories and daily online activities to companies that want our money, or, to benefit from our use of their services with lucrative ad deals or sales of personal information.

2. We create and/or consume interesting content on their services, but we aren't adequately rewarded for our creative efforts or loyalty.

3. We pay money to be connected online (and possibly also over mobile), yet we lose both time and money by allowing companies to market to us with unsolicited advertisements, irrelevant product offers and unfairly structured service pricing plans.

  • Archives