Ultrashock Tutorials > Flash5 > Flash5 for Coders  
 
By: Jason Krogh, zinc Roe design


PDF file

 
Flash5 for Coders
 

 

I recently tried to explain my career to my father who seemed to have a little trouble with the whole notion. My father is a geologist and one line which seemed to work was this. It's as if you were a geologist in a strange universe where the planet was pulled out from under you and replaced with a new one every couple of years. Well, welcome to the planet Flash5.

Flash5 Actionscript bares little resemblance to the code of old. In fact, it is most similar to javascript and was based on the open standards specification for javascript called ECMAScript. What does that mean? Well, it means we have evolved past the "MacGuyver" days when doing anything complex involved pulling out the duct tape and 9 gauge wire.

Lets take a quick looks at just a few of the features which stand out for the coders.

Goodbye TellTarget, SetProperty, GetProperty

In Flash4 it was sometimes useful to think of movieclips as objects. In flash5 movieclips can really be treated as objects. The old ways of targetting are over and while the new system may take a little getting used to it is far more powerful. Movie Clip instances can be referred to using dot syntax and have a set of methods (e.g. loadMovie(), hitTest(), etc.) and properties (e.g. _x, _xscale, etc.).

Here are some good examples:

Flash5 Flash4
_root.menu.item1._alpha = 50; Set Property ("/menu/item1", Alpha) = "50"
xpos = _root.menu._x; Set Variable: "xpos" = GetProperty("/menu",_x)
_root.menu1.gotoAndStop (5);
Begin Tell Target ("/menu1")
  Go to and Stop (5)
End Tell Target

The MovieClip Event

Flash4 provided two basic contexts for your code - it was either associated with a button or else it was part of the timeline. There is a new place to put code in flash5 - on instances of movie clips. This makes it possible to write code that is performed when a movie clip is first used (instantiated), on every frame as it plays, or whenever a key is pressed. There is a whole list of such clip events.

Remember the famed 3-frame movie clip from flash4? One of the reasons we relied on that trick was if we had a set of actions we wanted performed on every single frame. Now we can place that code on the instance of a movie clip. We can also make use of the keyboard clip events to trap and track keyboard input in a much more powerful way than we had in flash4.

XML

Extensible Mark-up Language is everywhere these days. It is an impressive technology which is actually very simple. Just as HTML represents information and how it should be displayed - XML represents information and its structure. How you treat the information is up to you. The key is that the tags give you clues as to what the data is. Here's a simple example:

<msg>
<to>Buddy</to>
<from>Schmoe</from>
<body>What kind of a name is buddy?</body>
</msg>

XML is a very handy way to exchange data structures because it is flexible and easy to read and handle. It can be generated and read by a wide variety of applications and there are plenty of free tools available to play with it.

Flash5 allows you to read in XML from an URL and then have access to all the data it contains. It is also possible to pass XML via socket connections for real-time applications like chat or multi-player games. This makes it much easier to pass data sets between a flash interface and a database back-end.

Wrap Up

For more experienced programmers flash5 represents a huge move forward. They can apply their knowledge of modern programming languages to Actionscript. For those who come from a non-programming background, the new version may look daunting. Many users won't stray from the basic set of actions, but for the rest of us it's going to be a fun trip!

 
©2001 Ultrashock.com Inc. - All rights reserved