Welcome to Mediasparkles

News : Flash

HelloWorld in AS 2.0 - How to write a simple AS 2.0 class

And I mean really simple. No type definitions, no private methods, just the basics. We can worry about the rest later.

AS 2.0 uses self-contained classes instead of stray code on key frames. Each class must be put in its own .as file, and the name of the .as file must match the name of the class. Example: MyFirstClass.as will contain a class definition for the class MyFirstClass. Now that we understand that part, let's write our first class.

A class declaration looks like this:

class ClassName {

// a method of this class
function aMethodName() {
// some stuff here
}

// another method of this class
function anotherMethodName() {
// more stuff here
}

}


So if we want to write a HelloWorld class, we could do something like this:

class HelloWorld {

// the method that says hello
function sayHello() {
trace("Hello World.");
}

}


We already know that we have to save this class as HelloWorld.as. But where do we save it? Anywhere we want. We just have to make sure that the .fla that uses this class, knows where to find it. We will get to that in a second.

First let's create a directory for our classes. How about My Documents/ASClasses/Practice. Save the file in the Practice folder as HelloWorld.as. Now we can create the .fla file that uses the HelloWorld class. The name of the .fla doesn't have to match the class name; it can be anything you want.

The first thing we have to do in the .fla is set the classpath. The classpath will tell Flash where to find the classes. If you are familiar with Java, you should know exactly what I'm talking about. To set the classpath go to File > Publish Settings. On the Flash tab, click on the Settings button next to the ActionScript version drop-down menu. In the ActionScript Settings dialog, click on the plus to add a classpath (you can have more than one). Then click on the icon that looks like this:
Browse to Path
Now navigate to your My Documents/ASClasses/Practice folder or wherever else you saved HelloWorld.as. Click OK. This will set the local classpath for this particular .fla.

To create an instance of the HelloWorld class in your movie, put the following:

MyHelloWorld = new HelloWorld();

Then you can call its methods like so:

MyHelloWorld.sayHello();

When you go to Control > Test movie now, the output window should spit out “Hello World.” And that’s it. You have just written and used your first AS 2.0 class.

Next week: What’s the deal with public, private, static and dynamic?

 posted by Vera (8/29/2003 02:57:00 PM);




TextField.mouseWheelEnabled and the scrollbar component

Will TextField.mouseWheelEnabled work with the scrollbar component? That's what I have been wondering. I thought that I might have to go into the meat of the component and tweak its code in order to get the new property to work in Flash Player 7. I did a little test and it was much simpler than I expected: You don't have to do anything. The scrollbar works with the .mouseWheelEnabled property natively. Nigel was really looking ahead there.

To use .mouseWheelEnabled with a text field that uses the scrollbar, do the following:

1. Create a dynamic text field on the stage and name it my_txt.
2. Drag a scrollbar component from the Components Panel to the stage so that it snaps to the text field that's already there.
3. Make sure that the text field is selectable and that multiline is selected.
4. Add the following code:

my_txt.mouseWheelEnabled = true;
my_txt.text = "Put lots of text here to make sure the scrollbar becomes active";

5. Test movie.

Voila! It works. It's a little bit buggy in that the scroll thumb doesn't always move all the way up or down when the text is scrolled using the mouse wheel. But it does work.

Note: You must first select the text before you can scroll it with the mouse wheel. This is why the text field has to be selectable.

 posted by Vera (8/27/2003 09:52:00 AM);




The big announcement: MX 2004

The cat is finally out of the bag: Macromedia announces Macromedia Studio MX 2004, which will include Flash MX 2004. If you're a programmer, you might be interested to know that ActionScript has been upgraded to ActionScript 2.0:
Take advantage of ActionScript 2.0’s more robust programming model and object-oriented programming support, which makes it more familiar to experienced Java programmers.

Also, trust me when I say that the new JavaScript API will be your new best friend. You'll see. In the meantime, check out some of the other new features as there are tons of them.



 posted by Vera (8/25/2003 07:18:00 AM);




Redesign

I redesigned it! What do ya think? A little more grown up, isn't it?

About the graphic in the top left corner: That's a picture of some flowers I had in the vase of my VW beetle earlier this year. For those of you who don't remember: That's also the beetle whose name is Flash.

 posted by Vera (8/24/2003 10:02:00 PM);




ActionScript.com/Reference

ActionScript.com is introducing the ActionScript reference section. It's like PHP.net but for ActionScript. It's like Flashdoc and Javadoc but with user comments. It's like ActionScript: The Definitive Guide but it's online and free! AND it includes components.

 posted by Vera (8/23/2003 08:11:00 PM);




FlashKit 2003 Day 2

Today was Day 2 of the FlashKit conference in San Jose.

Chris MacGregor did the keynote, titled Success Starts With the User. He likened the user interface to a waiter in a restaurant.

Slide from Chris MacGregor's keynote

Chris did a very laid-back keynote while wearing a snappy suit, which gets him definite points as a speaker. His talk about usability and the user experience was so inspiring that a little later, when Sas and I visited the bathroom where, in order to determine if a stall was occupied or not, we had to bend down to look for feet, Sas remarked that the bathrooms had an aweful user interface.

Next up was Mike Lyda of Cisco Systems with a presentation titled ActionScript Performance Best Practices. He gave us a list of about 30 tips that can help optimize ActionScript performance. Here are some of the ones I thought not everybody might know about:
- Export movies without trace actions by selecting Omit Trace actions from the Publish Settings.
- Use TextField.length rather than TextField.text.length to get the number of characters in the text field.
- Make calls to external Javascript functions for intensive processing. (Who knew?)
- Use short variable names. (Short function names don't make as much of a difference though.)
- Instead of
for (var i = 0; i < myString.length; i++) {
do something;
}

do this:
var theLength = myString.length;
for (var i = 0; i < theLength; i++) {
do something;
}
- If possible use if/else statements rather than switch statements.

For the entire list of Mike Lyda's performance tips, go here.

The next presentation I went to was Phillip Kerman's Exploring Practical Uses For FlashCom. He showed us a neat little online answering machine/greeting card where visitors can leave messages with plain text, audio and/or video. I also liked Phillip's presentation because I won one of his books, ActionScripting in Flash MX. I am glad I finally have my own copy of this book since I have been recommending it to several people who asked me how they should go about learning ActionScript.

I had lunch with the Electric Rain guys and with John Starkey, webmaster of FlashKit.

After lunch the Panel discussion took place. Aesthetics vs. Functionality: Where Should the Two Meet? Kristin Henry was the moderator, and the other panelists were Jonathan Kaye of Amethyst Research, Sas Jacobs of Everything Is Possible, Chris MacGregor, and Jessica D'Elena of Animax. Below is a picture of the panelists in action.

Kristin addresses a question from the audience

I spent the duration of the next presentation at Starbucks with Steve Ogden and Scott Manning, I'm afraid to admit. Oh well.

Finally, I saw Michael Williams, product manager at Macromedia, give his presentation on application development for Macromedia Central. Michael tells us that Central is in Beta 3 as of today, and that it will be released later this year. Scott Manning has a much better review of this presentation, so go read his.

After the conclusion of the conference, Scott Manning, Jon Williams and I talked Flash trash over Indian food for a few hours, and then I went home.

 posted by Vera (8/22/2003 11:19:00 PM);




FlashKit 2003 Day 1

Today was Day 1 of the FlashKit conference. The keynote was given by Macromedia's senior product manager, Forest Key. After talking about the present state of Flash, he also gave us a little future splash of what we should expect from future versions of Flash:
1. More focus on states instead of the timeline since the timeline has become a somewhat outdated metaphor which only really works for animation.
2. Being able to export directly to .swf from Final Cut Pro.
3. A video component that allows you to scrub the movie back and forth in real time.
4. Automated routines/scripts for transitions, effects, and events, similar to behaviors in Dreamweaver, and 3rd party extensions for 3D, text animation, etc.

After the keynote, I went to Danny Franzreb's presentation titled Introduction to XML in Flash. I didn't really feel like I needed an introduction but I wanted to show him my support since he traveled all the way from Germany for the conference. And I did learn something new from this presentation, which is that the first element in an XML document can't have any siblings. Didn't know that before.

Next I went to Robert Reinhardt's The New World of Flash. He showed us a cool project he has thrown together recently: a messageboard in which people can submit messages along with live audio and video streams of themselves. If you go to the post titled FlashKit 2003 San Jose, you will see a video of himself and the audience at the conference, which he recorded and submitted live during the session. I know it's a little blurry, but if you look really closely, you can see me in the audience.

Then I went to Jonathan Kaye's session on State Machines. Jonathan is a generalist whose presentations are very theoretical. I should really listen to him because I tend to just jump right into the code. He, on the other hand, didn't show any code but he did give away some CD's with very "valuable software" on it.

Bill Spencer aka Pope de Flash was supposed to be next, but he had to cancel at the last minute. Kick-ass designer Jim Foley of Electric Rain took his place and showed us some amazing 3D animations he has been working on. For a great example of Hollywood meets Silicon Valley, take in the Crime Scene clip at Flash Illuminations.

Scott Manning took the stage next. He talked about video. It was hilarious. He had some great old gems of videos featuring He-man and Transformers. He also gave all of us a copy of Muzak's Video Control component, which I have put to use in this nifty little video of myself hula-hooping:
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
WIDTH="240" HEIGHT="180" id="verahoopingMX" ALIGN="">
TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">

Lastly, I attended Sas Jacobs' presentation titled ActionScripting: Working With UI Components And External Data Sources. Sas is a Flash and ASP developer from Perth, Australia, who does business as Anything Is Possible. As the title of her presentation suggests, she talked about using components with server-side data, and she did so in a refreshingly un-object-oriented way. It made me feel all nostalgic about the days when ActionScript was exclusively procedural.

Besides Danny, Scott and Sas, I got to meet some more extremely cool people: Silke Fleischer of eHelp (yes, we share the same name and incidentally also the same birth month and year and country); David Emberton of ActionScript.com; Chris MacGregor of Flazoom; MD Dundon who is SO much fun; and several other speakers and attendees. After Sas' closing presentation, thirteen of us had dinner and margaritas at Pedro's. Towards the very end we were joined by Jim Foley, Steve Ogden and Paul of Electric Rain.

FlashKit 2003 posse
From left: Don Synstelien, Sas Jacobs, Jonathan Kaye, May-Li Khoe, me, Jon Williams, Chris MacGregor, Silke Fleischer, MD Dundon, Kristin Henry, Danny Franzreb, Nader Nejat, Scott Manning.

FlashKit 2003 dinner
Here we have the same group, but rearranged and with margaritas. I was lucky to sit next to Scott Manning and Chris MacGregor since both of them made me laugh constantly.

Mixmasters
Here we have Kristin, Chris, and Don scratching on their CD-ROM turntables.

My name tag
That would be me. Don't ask. Or if you must, ask Kristin. Thanks again, Kristin!

 posted by Vera (8/21/2003 11:22:00 PM);




At the FlashKit conference in San Jose

I'm blogging this live from the FlashKit conference in San Jose. I will be here all day today and tomorrow. If you're speaking or attending, come say hi. I would love to meet you.

 posted by Vera (8/21/2003 10:17:00 AM);




New SF buildings for Macromedia

Macromedia went shopping for buildings. This can only mean good things. Right?

 posted by Vera (8/19/2003 01:28:00 PM);