Archive for December, 2006

AS3: Communication between Flash 9 SWFs

Yesterday someone asked in Flashkit for a method to use assets from library hosting inside an external loaded SWF. It’s a question about communication between Flash 9 (AS3) SWFs actually.

As I don’t have a robust debugger for Flash 9 Alpha, what I talk here is just one of the method today I could use to communicate between AS 3 SWFs. It might easier to find more methods after Flash CS3 offically released in spring 2007.

In AS2, we can use _level0, _level1, and so forth, they pointed to different SWFs, so we can call them without any problem. But in AS3 it’s different (at least right now I couldn’t get similar idea from Flash 9 Alpha debugger panel.) . But I found a way to communicate each other easily. (I call here the main AS3 SWF is the _main one, and loaded AS3 SWF is a _sub one.)

The only connection I know right now from Flash 9 Alpha, is the median Sprite, for _main it’s the .content loaded, for _sub it’s the root, they’re the same object indeed. So the simplest way to communcate between _main and _sub, we can call functions through it. If we want to call something from _sub, we can call root.parent.somefunction() to do something. From another side, we call from _main with .content.somefunction() as well.

So I suggested him to call a function inside his external swf to create a new instance of the asset and return the reference back to main stage, thus he can addChild it anywhere. And it worked. Cool!

A Solution to Reduce CPU/Memory Usage For Script-based Animation

As we could see, script-based animation always used a big amount of CPU/memory, which affects the performance definitely. So is there a solution to optimize but not trade-off?

I reviewed Algorithms in Java these days and making algorithm collections for Actionscript 3.0 version, while I’m working on a Flash project which required lots of manually information of paticular frames. Today I think I got a solution that to get improved for this problem in some way.

Like the improvement methods for algorithms, optimization for script-based animation we could get ideas from small cases of analysis, decreasing unnecessary loops, cuting unnecessary instruments inside important loops. But in this post I’m not want for those, but a method, that if a script-based movement is not totally random, save data down into scripts in some way .

Several months before there’s a Dr. Woohoo made something to take out information from AE for Flash integration, I don’t use any AE script so I don’t understand what is that exactly. But it lighted me to have an idea to record information details for animation, but not everything to calculate expensive sin() cos() atan2() with scripts in Flash. From my experience of current project, I run testing and record the information I need in a particular format, and trace out in the end. Then I copied them back directly into arrays in actionscript, in this way no more complex calculation required. So here is a brief of my solution:

1. Do everything in scripts.

2. Plan the data format to be used directly back with actionscript, such as positions, scale, rotation, in array, an so forth. What I say, a format of Actionscript ready for copy. If they will be mostly constant, it’s easy, if not, think about a simple algorithm or some functions to use constant input to get dynamic arrays (or linked-lists).

3. Put record code inside your functions, trace out them in the end.

4. Paste data back into your actionscript code. Testing and tuning.

5. Comment all unnecessary functions. Because for Flash SWF file, cut down unnecssary code means decreasing final size (think about the size of v2 components), that means another improvement for loading time.

It’s clear not everything we could do optimization in this way, but we can do some parts of these jobs, while leave impossible missions for scripts calculation. What we need is improvement not perfect. Surfers don’t care what you made your Flash, they just don’t want a higher CPU/memory load, they just prefer silent, quiet, and neat.

In fact, the Flash IDE itself has a similar manipulation for animation. You can use easing graph for animation of movieclips, while Flash IDE will save positions, rotation, scale data for each frame, no calcuation required so. But it only for animation of those kinds of, if you want to change some kinds of behavior of easing, or 3D, you can do nothing with Flash IDE, you have to plan to save those data in your own way for complex situation especially script-based animations.

MsDewey, a Microsoft’s site in Flash design very cool with perfect neat dynamic videos. With Flash media server and high-speed servers, Microsoft could provide a large amount of Flash videos in flexible way.

Still it begin with a preloader, but display a FLV instead of normal progress bars. It’s a nice idea but if you copy the same way, not the deal whatever. And they should use cuepoints for progress points, so you wouldn’t feel bored to wait. While still, it’s funny this time, but it have to be changed if this is a long time service of Microsoft Live Search I guess.

I don’t know why each time refresh there’re something to download, possibly to load a dynamic beginning scene it will be played, or the Flash video of the beginning scene is usually too large to be load more buffer. It pretty interest each time they load a kind of different beginning scene before you can use Live Search. Also, there will be lots of dynamic Flash videos to be played while you’re searching even when you idle. The background is sticked with one image currently.

I like the design, a kind of implementaions of neat Flash ‘film’s, perfect reality. It’s a perfect sample usage of Flash videos. But it have to have big money to support media server clusters, high-speed network speed, as well as lots of video jobs.

Adobe Flash product manager Mike Downey pointed out the response of young lady should be some relatives to your search but not always. I think it’s the job of back-end but, it have to get response very quickly maybe from an existing list of words matrix like Eliza, but not based on the result of search(it need time before the lady could do anything), so it need time for Live Search to go extra miles.