Embedding JavaScript into a SWF
Posted by Kenny Bunch in ActionScript, Flash on September 25th, 2009
Developers that have been using Flex should be pretty familiar by now with the Embed metadata tag which allows you to embed assets into a SWF (like images, SWFs, XML, etc). This option has also been added to CS4 (CS4 uses the Flex SDK to complete this task).
What some of you may not know or though of, is that you can actually embed JavaScript libraries into your SWF and have your SWF write those libs to the pages DOM. We've been using this technique for a while. However, when someone asked for a reference on the subject, I searched the web and didn't find one. So here we are
.
This technique is quite simple. The basics of it are that you embed the JavaScript library using the embed syntax, then create a Class that references it when instantiated, instantiate that class, get the string representation of the instance, and send that string to the page to be embedded using a JavaScript eval statement.
To illustrate this, lets create a JavaScript file called hello.js which has a single function hello that throws an JS alert.
Hello.js
-
function hello()
-
{
-
alert("hello");
-
}
Now lets create the ActionScript file that embeds the JS into a SWF, writes it to the page, and calls the hello function in the lib.
-
package
-
{
-
import flash.display.Sprite;
-
import flash.external.ExternalInterface;
-
-
public class EmbeddedJavaScriptExample extends Sprite
-
{
-
// embed the JavaScript into the SWF
-
[Embed(source="hello.js", mimeType="application/octet-stream")]
-
// create a class that can instantiate the JavaScript for embedding
-
private static const HelloJS:Class;
-
-
public function EmbeddedJavaScriptExample()
-
{
-
if (ExternalInterface.available)
-
{
-
// embed the JavaScript to the page
-
ExternalInterface.call("eval", new HelloJS().toString());
-
-
// the embedded JavaScript has a function call named hello
-
// now that it has been embedded to the page call it
-
ExternalInterface.call("hello");
-
}
-
}
-
}
-
}
You can download the full example here.
Pretty nifty eh? Hope this shows you a neat little trick to use in distributing some of your SWF/JS libraries.
Bear on a Wire (previously Poor Bear) IPhone game released
Posted by Kenny Bunch in General, IPhone, Projects on September 1st, 2009
Bear on a Wire Trailer from bearzo on Vimeo.
The Game
Our first IPhone game, previously code named Poor Bear is officially available in the app store today under the name Bear on a Wire. For those of you who followed the progression of the game on our site (1, 2, 3, 4) know that this game didn't start with designs, requirements, deadlines, or the promise of gold bars. Instead it was built on the premise that we could make something fun that we molded just how we wanted it. That mold shifted and turned over time. Even at the starting gate, we didn't even know what type of game we were making. The game really grew organically and took on a life of its own. I'm personally blown away with the outcome, especially considering this was Chad's (the developer) first game and he went into it not knowing Objective C. The design is a work of art as well. However, for those of you know Trevor (the designer), know that you could expect nothing less. Words can't do justice to what 1 designer and 1 developer have done with this game. It is simply amazing and even though it is our own game, none of us can stop playing. That was the point though. We built something we loved. We hope you will too!
Support Us
We appreciate any support you can give us. For those with an IPhone grab the game now, rate it, and review it!
APP STORE: http://itunes.com/app/bearonawire
For those wanting to get the word out. Here are some links to blog, twitter, AIM, tell someone on a subway, etc. We will have flyers too that you can print and post on bathroom walls, telephone polls, and anywhere in eyes view.
SHARE THE BEAR!
APP STORE: http://itunes.com/app/bearonawire
SITE: http://bearonawire.com
TWITTER: http://twitter.com/bearonawire
VIMEO: http://www.vimeo.com/6367707
YOUTUBE: http://www.youtube.com/dreamsocket
Press Release
Dreamsocket & TVM Studio are excited to announce they have just released Bear On A Wire.
Apple app store link: http://itunes.com/app/bearonawire
About the game:
Our green hero, Bearzo, has had it! No more performing for "THE MAN" day in and day out. What! Do you think he is some kind of dancing bear? NO... he is a high wire bear, and it's time for him to make his great escape from the Big Top. He loves his fans and his work, but he just wants to be free and feel his scarf blow in the wind as he shreds wire with the most insane moves ever attempted ... on a Moped... on top of high voltage power lines. Get ready to feel the power of the 49cc, two stroke, and single cylinder stallion!
As you tear off on the wire, try to balance Bearzo and keep him from fallingdown into the 1.21 gigawatts that alternate through the wires below him (Ah, the smell of burnt bear hair). While balancing on the wire, acquire crazy mad points by using the different stunt key combinations to generate some MOPED MAYHEM (ECO..ECo..eco) Bearzo's stunts include no hands, half twist, full twist, bear buck, back roll, front roll, jump roll, grinder, spin roll, spin buck, spin buck grinder, coat tail, coat tail kick, and the next to impossible coat tail kick spin grinder. Combine these stunts with full flips, double flips... triple flips...? Now you are just being crazy! Collect coins and rack up even more points. I know...you never saw collectable coins coming. Don't get caught hibernating b/c it's about to get all GRIZZLY up in here!
Get pumped for BEAR ON A WIRE.
Presenting at the Flex User group in Atlanta tonight
Posted by Kenny Bunch in Uncategorized on April 29th, 2009
Its late notice, but better late than never. I will be presenting along with Alan Queen tonight at Atlanta's Flex User Group in Buckhead. Alan will begin the night with talking about dynamic audio with Flex/Flash/Air and then I'll close it out talking about general media applications and our framework.
The meeting starts at 6:30 and is at
Echo Eleven's offices
3525 Piedmont Rd NE
Building 7, Suite 400
Atlanta, GA 30305
The meetup site has more details. Definitely come out if you can, it looks to be a great meeting! If you do, make sure to RSVP as it looks like the list is pretty large right now.
Collision Detection and Poor Bear
Posted by Kenny Bunch in Uncategorized on April 15th, 2009
Chad posted a nice article on Dreamsocket.com outlining some problems he was trying to solve with doing collision detection and his solution. It is an interesting read and gives you some technical insight into some of our development process with Project Poor Bear. Check it out when you get a chance.
Media Framework license and pricing changes
Posted by Kenny Bunch in ActionScript, Flash, General, Projects on April 2nd, 2009
Today we introduced a new license and pricing model for the Dreamsocket Media Framework.
The new license model:
- $99 - Individual
- $350 - Small Business (2 - 20 employees)
- $895 - Midsize Business (21 -50 employees)
- $1895 - Large Business (51+ employees)
To see all the details of the change and why we did it, check the post over on our site.
If you haven't checked out or grabbed your copy of the product, now is a great time!
Clean Media Framework Documentation on Dreamsocket.com and in AS2 1.1.68 and AS3 1.1.84 release
Posted by Kenny Bunch in Uncategorized on April 1st, 2009
We updated all the ActionScript Media Framework documentation on the site today along with all the documentation in the product downloads. Though we put out a new release, nothing really changed but the docs and those changes were simple. We removed all uncommented private/protected class properties from the documentation. This makes reading the documentation less of a headache since its less clutter.
Anyone that saw our earlier post on the as2api source code changes, some of the capabilites that allowed us to selectively clean up the ActionScript 2 code base are in that post. Good times
.
Stay tuned for more goodies!
Modified as2API source and binary posted
Posted by Kenny Bunch in Uncategorized on April 1st, 2009
We modified the as2api doc tool for ActionScript 2 to include hiding/showing private members, events, and @private tags. The source and information is posted over at Dreamsocket. If it is useful to you, go read about the changes and grab it!
Project Poor Bear Update 3 posted
Posted by Kenny Bunch in Uncategorized on March 31st, 2009
We posted progress on ole Poor Bear over at Dreamsocket. However, we don't want this to be a one way communication outlet on what we are doing. We want you involved. Go check out the post and share your ideas on elements of the game. Help us make Poor happy!
Media Framework Solution: Cartoon Network and Jetstream Video Gallery
Posted by Kenny Bunch in Uncategorized on March 30th, 2009
Our site has a solutions section that showcases sites and applications where we have used our media framework in the past. In a way it provides a glimpse into the legacy and evolution of the framework. Unfortunately it doesn't paint the entire picture, as our largest and most notable solutions haven't been posted due client PR departments. Sometimes we get a break, mind sets change and we get the privilege to show them out of the blue. Today was one of those days when PR mindset changed. Many thanks to Jim and Paul for making this happen for us.
Long story short, we posted the Cartoon Network and Jetstream video players we developed to our solutions page. Though these applications are about 3 years old, they still tell an interesting story. When first developed, they utilized Windows Media through an abstract bridge in Flash. The conversion to Flash video was actually seamless in that we didn't change code, we replaced the internal "playback".
Project Poor Bear designs posted
Posted by Kenny Bunch in Uncategorized on March 26th, 2009
We made a new post over at Dreamsocket which contains new designs, animations, and creative write up on our IPhone game (Project Poor Bear) that is currently in progress. Trevor has some great insights into his thoughts for the game. Go check it out!

Subscribe to RSS