ExternalInterface.call not working with IE

While working on a few PhotoSnack albums a few days ago, I’ve tested some features with several browsers but noticed that with Internet Explorer the albums were not working as supposed to. Specifically, the ExternalInterface.call() function wasn’t calling the target JavaScript functions at all.

After testing the JavaScript and ActionScript functions separately, it seemed they all worked without any problems. Anyway, the JavaScript functions were being called with no problems on all the other browsers I tested, except on Internet Explorer. After searching the problem on the Internet I came upon a comment on the ActionScript 3 documention posted on Adobe’s livedocs for the ExternalInterface class (thanks gerdy).

It looks like for the ExternalInterface.call() function to work in IE, the embedded Flash object MUST have the id attribute specified. Otherwise you won’t be able to display not even a JavaScript alert message from Flash. As soon as the id attribute was set for the flash objects in PhotoSnack, the albums worked just fine with Internet Explorer too.

So, as a best practice, I recommend always setting the id attribute of your Flash objects embedded in HTML pages.

Google, can you hear us ?

We’ve just launched a petition on Facebook: we would really like for Google to allow ActionScript 3 .swf files for AdWords. If we scream loud enough, maybe Google will hear us. So please, those of you who have a Facebook account, sign our petition. If Google will allow AS3 .swf file for its AdWords system, we will all benefit.

Thanks to all of you.

New PhotoSnack, BannerSnack and SnackTools release

Yesss !! Finally it’s here. We’ve been working on these new versions for a few month and last evening (local time) we finally released them: SnackTools, BannerSnack and PhotoSnack.

It took a bunch of great people working for many hours for the past few month. I have to thank my colleagues from the Flash and PHP department for making this possible (and for the many extra hours put into this new release), not forgetting Alin, the product manager for PhotoSnack who came up with the many great features of the entire application, the workflow and the photo albums, Raul who helped us with the design and workflow for PhotoSnack and who is the product manager for BannerSnack, Tibi our great web designer and of course the marketing department without whom, many of you wouldn’t have heard of BannerSnack and PhotoSnack.

Thank you guys, we really make a great team :D.

As for the new releases, you’ll notice a great difference between the new and the previous versions. Now, you can have access to any of those SnackTools apps from the same account, which is a SnackTools account. The new design optimizes the workflow within the web applications so you can make the best of them. You should check them out. Of course, we tried as much as possible to leave your existing banners and albums exactly how you made them.

PhotoSnack comes with a few more photo album templates and new features like downloading a published album and improved publishing system. You can check out the new features here. BannerSnack also comes with new features like a new and improved workflow, undo/redo actions and improved transition effects. The publishing system has features that are only available by purchasing SnackTools points so you no longer have free or premium accounts.

All that’s left to do is for you to try them out. Of course we are always interested in what you have to say about our SnackTools apps (ideas, comments, feature proposals) just send us an emai at contact@snacktools.com or leave a comment to this post.

SnackTools, PhotoSnack and BannerSnack has just been launched for testing

Finally… I’m in the mood of writing again… I’m sorry to say that it’s a long time since my last article, but hopefully that is going to change.

A lot has happened in the Flash world these past few month and I’m sure you’re up to date with the news so there’s no need for me to list them.

Anyway, if you noticed, during the summer JumpeyeComponents launched a new web application called PhotoSnack. It allows you to create very nice online Flash photo albums. Well, JumpeyeComponents has just launched an updated version of PhotoSnack for testing, which can be found at http://dev.photosnack.net. It has many more features than the initial version and a total of 13 albums to choose from. Here is a short video to get you started: http://dev.photosnack.net/help/tutorials/getting-started/.

Besides PhotoSnack, JumpeyeComponents also launched the SnackTools, which is a suite of web applications containing both PhotoSnack and BannerSnack. All of the web applications are only for testing purposes and JumpeyeComponents is happy to receive your feedback on the applications. There’s also a full-discount coupon (TEST) used to unlock the premium features.

One important thing to note is that the accounts you create in the test applications will be deleted without any notice once the testing is over and the applications are released in their final version. Just keep this in mind while you are playing around with the apps.

This being said, I hope you’ll all have fun with the SnackTools. I’m looking forward to see some interesting examples. If you have any comments on the applications (ideas, bug reports or any other comment) feel free to leave a note here or write to JumpeyeComponents through the feedback application they have on each of the SnackTools web apps.

FlashEff2 officially launched

Today JumpeyeComponents has officially launched the next version of the popular Flash animation tool – FlashEff. Now it has a redesigned workflow that makes life even easier and comes with a solution to lower the file size of your Flash clips: the FlashEff2 component has a lower size than the predecessor and it comes with another set of components – FlashEff2 Light.

The FlashEff2 Light pack contains separate animation components, each one specialized to do one of the main component’s jobs: show/hide animations for symbols, show/hide animations for texts, applying filters, creating buttons and executing commands. So you can use only that one feature you really need for your project without having to import all the FlashEff2 features into your Flash clip. This way you can lower the file size of the final animation even more.

Here are some other features for FlashEff2:

  • a large number presets that you can choose from (3000+ presets)
  • the possibility to tweak those presets or to make your own settings
  • create and save your own custom effects which you can reuse any time you want
  • a completely new button mode

Here you can find more information on the component’s features and watch some nice video tutorials that will help you get started with FlashEff2. There’s even a nice video on the home page based on the comments users left on this JumpeyeComponents blog post.

ActionScript NetConnection Error #2044: Unhandled AsyncErrorEvent

I’m testing the Red5 server to see how to use it for audio and video streaming but right after testing the connection to the server, I get the following error message in my Output Panel (though the connection to the server has been established correctly):

Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetConnection 
was unable to invoke callback onBWDone. error=ReferenceError: Error #1069: Property 
onBWDone not found on flash.net.NetConnection and there is no default value.

After digging around it seems that I didn’t specify the client for the NetConnection object:

netConnection.client = this;

After setting the client property, all was well. So don’t do the same mistake as I did.

ExternalInterface: Flash – JavaScript communication

There are situations when you need to create a web application that is part Flash, part HTML, like some handy widget that must reside in an HTML page and that would also have to communicate with it. The next example presents a simple color setting widget made with Flash, which communicates with the web page it is integrated in. Basically the Flash widget contains three slides to set the RGB color value and the composed color is displayed in the HTML page, in a text input control. The user also has the possibility to enter a hexadecimal value of a color in that text input which will set the sliders in the Flash widget to the corresponding values. Flash – HTML communication (actually ActionScript – JavaScript communication) is possible by using the ExternalInterface class within the flash.external package.

The ExternalInterface class was created to replace the older fscommand() function and can be used to call JavaScript functions from ActionScript or call ActionScript functions from JavaScript. It is also able to transmit a return value from the function being called to the code (ActionScript or JavaScript) calling the external function. It is much more flexible than fscommand() since it allows calling any JavaScript function defined in the HTML file with any number of arguments (of various data types), while fscommand() allowed calling a limited number of functions with a single String as argument. Also allows receiving a return value from the JavaScript function call to ActionScript and vice versa.

Calling a JavaScript function from ActionScript is quite easy. All you have to do is call the static call function of the ExternalInterface class:

ExternalInterface.call("myJSFunction");

You can even specify function parameters and receive the return value, like this:

import flash.external.ExternalInterface;
var value:String = ExternalInterface call("myJSFunction", param1, param2, param3);

Of course this means that in the HTML file containing your Flash clip there has to be a JavaScript function defined with the name of “myJSFunction”. In the above example, we presume that the type of the return value of the JavaScript function is a String, but the ExternalInterface class allows receiving other types of values too.

Calling an ActionScript, from within your HTML document using JavaScript is equally easy. All you have to do is get a reference to the Flash object embedded into the HTML document and then call the ActionScript function directly on this object. Of course, this requires that the ActionScript function is defined as a callback function for the JavaScript code, in the main timeline of the Flash clip:

ActionScript code:

ExternalInterface.addCallBack("myASFunction", someASFunction);

JavaScript code:

var flashMovie = window.document.MyFlashWidget;
flashMovie.myASFunction(value);

In this case, the name and id attributes of the Flash object must be set to “MyFlashWidget”. Another requirement for the HTML document is to set the allowScriptAccess attribute of the Flash object to “always”.

“myASFunction” is the function name that the external JavaScript code must call, but the actual name of the ActionScript function is “someASFunction”. This way, external JavaScript code can only have access to the ActionScript code that the developer allows to. Also, in this case, if the ActionScript code must change and the “someASFunction” function is removed, there could be another function passed to the addCallBack method. Thus, it is ensured that “myASFunction” always gets called by JavaScript and that Javascript can actually be oblivious to the changes of the ActionScript code.

One more thing worth mentioning is that it is a good practice to check if the JavaScript code is available for calling, before actually making any calls to it. This way possible errors or malfunctions are avoided in the application:

if (ExternalInterface.available) {
	try {
		ExternalInterface.addCallback("myASFunction ", someASFunction);			}
	catch(e:Error) {
		// Callback function could not be added for various reson.
		// You could treat this situation here.
	}
}

You can download the full example from here. I hope it will help out some of you.

Update: For Internet Explorer you should make sure that you specify your embedded Flash object the id attribute, as mentioned in this post: ExternalInterface.call not working with IE.

ActionScript 3.0 and Flex optimization

I’ve just found an article on InsideRIA that is actually a list of techniques and best practices for optimizing ActionScript 3.0 code and Flex applications. This is a must know for AS3 / Flex developers. The article has a list of references – information on which the article was based. I really recommend you reading through those articles and also through the comments to the article. You’ll find there a few more links to optimization articles and some extra notes on the information in the article.

Update: Grant Skinner has also published an AS3 performance tester. You might want to check it out. Oh, and I had another post about an interesting AS3 performance tester application. There’s a wiki page too, created by Joa Ebert, listing some AS3 optimization tips.