Essential ActionScript 3.0

Colin Moock

Mentioned 25

A guide to ActionScript programming covers such topics as conditionals and loops, functions, datatypes, interfaces, event handling, namespaces, XML, Flash, programmic animation, and bitmap programming.

More on Amazon.com

Mentioned in questions and answers.

So I'm starting an internship as a Flex developer in ~2weeks thanks to a friend of mine. The thing is I know squat about Flex - it is an internship after all so I'm supposed to learn there, but nonetheless I want to have some basic understanding of Flex before I start (eventually I want to become a JEE/Flex dev).

So my question is simple, which book(s) would you recommend me to start with? Are there any "must have" books, like let's say "Thinking in C++" for C++ etc.? I already heard about a few video tutorials and I will surely check them out but I'd also want to get some decent books.

For getting started with AIR and Flex:

This link contains free online videos about flex ,it is very useful for learn flex quickly

www.Adobe.com

Essential Guide for Flex,

http://www.ebook3000.com/The-Essential-Guide-to-Flex-3_21697.html

For Flex:

Programming Flex 3,

http://www.amazon.com/Programming-Flex-Comprehensive-Creating-Applications/dp/0596516215/

ActionScript

Essential ActionScript 3,

http://www.amazon.com/Essential-ActionScript-3-0/dp/0596526946/

(considered the ActionScript bible)

The Beginners guide, http://www.ebooksdownloadfree.com/Flash-and-Flex/Flex-3-A-Beginners-Guide-BI269.html

This link contain tutorial of flex, http://www.diesel-ebooks.com/cgi-bin/item/0321482972/Adobe-Flex-2-Training-from-the-Source-eBook.html

This link contain how to learn flex for all level learners,

http://seantheflexguy.com/blog/2009/02/27/how-do-i-learn-flex/

http://www.squidoo.com/adobeflex

Learning Paths | Adobe Flex Developer Center

https://www.adobe.com/devnet/flex/learn/

Hope that helps..This will surely help u..Try now..

I read Adobe Flex 3: Training from the Source as my first Flex book.

You might also think about getting a membership to Safari Books Online. Then you can read several different books at a time on different topics and not have to buy the actual books. If a book you picked sucks then you can pick another one and not waste another 40-50 dollars.

FYI - These expenses are tax deductable so hag onto the reciepts.

One of my favorite books is by James Ward who is pretty active here on Stack Overflow and works as an evangelist at Adobe - http://www.amazon.com/First-Steps-Flex-Bruce-Eckel/dp/0981872506

He wrote it with Bruce Eckel so if you liked thinking in C++, then this might be a good book for you. I think James has some free copies to give away, so if you drop me an email I can check with him and potentially have one sent out to you.

=Ryan ryan@adobe.com

I've been programming with ActionScript 3 for a little while and I've noticed that the natural progression of my code seems to take the form of one giant document class with dozens of member variables, callbacks, and handles to objects on the stage. In short: it's kind of a mess!

Thing is, I don't really see a way around it (not yet at least). I use different keyframes on the timeline to represent different states in an app, and while I have some code right on the timeline (for quick things like a mouse click on a movie clip), most of the logic just ends up dumped in the main document class.

So, I'm wondering... What are some good ways to help neaten up this code-gone-wild? Or is this normal? I come from a C++ background, and I like writing object-oriented stuff, but I can't see a way to carry over that kind of structure to Flash. Any insight would be really appreciated.

Thanks

Since your from an OOP background you shouldn't be having this problem. However that is easily fixed with a quick read through a couple great books.

Essential ActionScript 3.0 http://www.amazon.com/Essential-ActionScript-3-0-Colin-Moock/dp/0596526946

ActionScript 3.0 Design Patterns. http://www.amazon.com/ActionScript-3-0-Design-Patterns-Programming/dp/0596528469

With your OOP background these are perfect.

If your getting one big file the obvious think to do is to begin by breaking things down into classes.

You would be wasting your time with MVC or any other design pattern without being able to reliably code OOP in AS3.

I am an Ajax developer and I want to build a Flash application. Given my previous experience with JavaScript, what do you thing will be the easiest way to learn ActionScript and what are the obstacles I might encounter?

My advice would be to download a copy of FlexBuilder and stick to AS3. AS1 and AS2 are now irrelevant and not used to develop "Flash application" anymore. don't waste your time reading about it, it might confuse you.

There are a lot of resources available to learn Flex, just google it. The best book i had to read about the subject is Essential ActionScript by Colin Moock. It is a reference

But most of all, code, code and code again.

You might try to port some of your previous projects as a good learning exercise.

Good luck with your learning.

I am a Java developer. I am good at learning new languages but I can't make head or tail of AS3. It seems like a different mindset that I can't get into or something.

Could you provide links a AS3 tutorials that explain everything well, preferable targeted for people who have already programmed?

Thanks so much.

Here are some online links:

A few chapters form Colin Moock's DVD series
Getting started with ActionScript3
Language reference

If you are really serious about getting into it, I highly recommend picking up Colin Moock's book Essential ActionScript 3.0 I think its the best book you can buy.

Enjoy!

I have a large codebase that targetted Flash 7, with a lot of AS2 classes. I'm hoping that I'll be able to use Flex for any new projects, but a lot of new stuff in our roadmap is additions to the old code.

The syntax for AS2 and AS3 is generally the same, so I'm starting to wonder how hard it would be to port the current codebase to Flex/AS3. I know all the UI-related stuff would be iffy (currently the UI is generated at runtime with a lot of createEmptyMovieClip() and attachMovie() stuff), but the UI and controller/model stuff is mostly separated.

Has anyone tried porting a large codebase of AS2 code to AS3? How difficult is it? What kinds of pitfalls did you run into? Any recommendations for approaches to doing this kind of project?

Here are some additional references for moving from AS2 to AS3:

Grant Skinners Introductory AS3 Workshop slidedeck http://gskinner.com/talks/as3workshop/

Lee Brimelow : 6 Reasons to learn ActionScript 3 http://www.adobe.com/devnet/actionscript/articles/six_reasons_as3.html

Colin Moock : Essential ActionScript 3 (considered the "bible" for ActionScript developers): http://www.amazon.com/Essential-ActionScript-3-0/dp/0596526946

mike chambers

mesh@adobe.com

What more can be done if I extend MainClass with MovieClip rather than Sprite. I know that MovieClip extends Sprite and it has Timeline defined under it. but still how it will be usable to me by MovieClip ?

package  {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.display.MovieClip;
    import flash.text.TextFieldType;

    public class MainClass extends Sprite{      
        public function MainClass() {   

            var m:Module=new Module("Admin","John");

            var tf:TextField=new TextField();
            tf.text=m.info;
            tf.border=true;
            tf.type=TextFieldType.INPUT;

            var myFormat:TextFormat = new TextFormat();
            myFormat.size = 3;
            tf.defaultTextFormat=myFormat;

            addChild(tf);   
            this.width=500;
            this.height=300;
            this.x=0;
            this.y=10;
        }
    }       
}


class Module{
        private var m_mName:String;
        private var m_owner:String;

        public function Module(mName:String,owner:String):void{
            m_mName=mName;
            m_owner=owner;
        }
        public function get info():String{
            return owner+' is owner of '+mName;
        }
        public function get mName():String{
            return m_mName;
        }
        public function get owner():String{
            return m_owner;
        }       
    }

Another little question, How to use Timeline if I replace Sprite by MovieClip ?

Quoting from an AS3 book:

Prior to ActionScript 3.0, the MovieClip class was used as an all-purpose graphics container (much like ActionScript 3.0s Sprite class is used). As of ActionScript 3.0, MovieClip is used only to control instances of movieclip symbols created in the Flash authoring tool. Because ActionScript 3.0 does not provide a way to create timeline elements such as frames and tweens, there is no need to create new empty movieclips at runtime in ActionScript 3.0. Instead, all programmatically created graphics should be instances of the appropriate core display class (Bitmap, Shape, Sprite, TextField, etc).

MovieClip is a dynamic class that retains backwards compatibility with AS2. That means that if, while not recommended, require you add a property to a MovieClip, you can simply say myMC.myCustomProperty = "someValue", whereas with a Sprite, that will throw an error.

For this reason, they also say that using Sprites is more effective in terms of performance. You can find a discussion about this in this Adobe Forum post.

I am new to actionscript 3.0 and I'm experiencing difficulty trying to pass a variable that is created and set in frame 1 to a dynamic text box that is added to the stage in frame 4.

on frame 1 the variable is set from information entered by the user: var input_dia = ""; input_dia = pdia_input.text;

and should be displayed in a dynamic text box on frame 4: dia_alert.text=input_dia;

I'm receiving the following error: 1120: Access of undefined property input_dia.

frame scripting is, in my opinion, ghetto and should be avoided.

that being said, you problem could be solved a few ways. first, you create an "Actions" layer that is accessible to all frames by stretching the layer as long as your timeline, but all your actionscript is on the first frame. second, by placing your text field on a separate layer, accessible in frame one but only becomes visible in frame 4 (assuming you don't want it to appear until frame 4).

however, OOP and and a descent design pattern as Glycerine suggests is definatly the way to go, especially if you are new and plan on further investment in the flash platform.

some book suggestions: Colin Moock's Essential ActionScript 3.0, The ActionScript 3.0 Quick Reference Guide, Kieth Peter's Foundation Actionscript 3.0 Animation: Making Things Move! and AdvancED ActionScript 3.0 Animation. these books will certainly give you some solid ground in proper development for the flash platform. if you read them you wont regret it.

Possible Duplicate:
Beginner Actionscript reference

Hi everyone, could you please help me, how can I learn ActionScript 3.0?

I know Flash very well, but I don't know ActionScript.

buy/read books. learn the right way as well as starting your own developer's library that you can reference from years to come. don't waste your time with sporadic, often misguided or incomplete online tutorials.

i recommend the following:

  1. Appitizer - ActionScript 3.0 for Adobe Flash Professional CS5 Classroom in a Book
  2. Full Course Meal - Essential ActionScript 3.0
  3. Desert - Adobe Flex 4: Training from the Source, Volume 1
  4. Icing - Actionscript 3.0 Animation: Making Things Move
  5. Updated Icing - AdvancED ActionScript 3.0 Animation

I'd suggest you start off with the basics.

Here is an excellent link:

http://www.kirupa.com/developer/flash/index.htm#ActionScript_Basics

With that, you need to understand datatypes and how they work. Flash is a strongly-typed language, so you need to keep track of datatypes at all times.

This is the reference for the current (Flash Player 10) build of Actionscript 3.0 (compatible with Adobe Flash CS4 and up):

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/index.html

I'd suggest you start off the the flash.display section. That contains the classes beginners are most familiar with, those of course being flash.display.MovieClip and flash.display.Sprite. Here's a link to that package:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/package-detail.html

Primarily, you need to have a extensive knowledge of the following in Flash to be successful:

  • MovieClips
  • Sprites
  • Arrays
  • ints
  • Numbers
  • Strings

With a good knowledge of those datatypes, you should be well on your way. I guess a good question here would be "how familiar are you with programming logic?". Actionscript 3 is a direct descendant of the ECMAScript spec, ergo, a sibling to Javascript. They each have their own special quirks, but Actionscript 3 and Javascript are quite similar. I've found when learning them in conjunction, comprehension comes much quicker than learning them separately.

Failing these online resources, Essential Actionscript 3.0 by Colin Moock is a must in my opinion. It's a wonderful reference with well-detailed examples that will get you off the timeline (presuming you were on it to begin with) and into Object-Oriented Programming.

Google Books has a free preview of that book here:

http://books.google.ca/books?id=gUHX2fcLKxYC&printsec=frontcover&dq=essential+actionscript+3.0&hl=en&ei=BkVGTcPYPIP4sAOOwMSgCg&sa=X&oi=book_result&ct=result&resnum=1&ved=0CC4Q6AEwAA#v=onepage&q&f=false

Finally, just use Google for any quick snippets or questions you're looking for. I've found googling "(your problem here) as3" can have sufficient results for smaller, more popular issues. Good luck!

-Matt

I need to familiarize myself with this technology. My problem is that Google is swamp with results for tutorials. Where should I start?
What development environment should I use assuming this is only for learning purposes and I don't want at the moment to buy any expensive software?
What tools should I use?
Any road maps for dummies?

Flex for dummies...

alt text

But seriously figure out a simple flex application you want make and make it. That is the best tutorial. Then when you get stuck you will have a specific problem you are looking to solve. The myriad of tutorials on Google will then begin to make sense.

I like the book Flex 3 from the Source. After you have a little bit of context for Flex, check out the Flex Examples blog.

I really think that "learning Flex" is a mistake. Focusing up on core Actionscript 3 skills is essential to long term success with the Flex framework. You will find that you rapidly hit a wall where "knowing Flex" without the underlying language core will be an extreme disadvantage. If you have prior experience with a statically typed language, the AS3 shouldn't be difficult. All of Flex is written in AS3, and analyzing the underlying codebase is the best way I have found to learn the framework.

Essential Actionscript 3 is the best place to start down that path.

In trying to learn how to create objects in ActionScript, I have had no success. One thing that I have noticed is that there seems to be a billion different ways of doing it. Even if none of them have worked for me. This is really confusing me, and I don't know which approach to try to debug.

The approach that seems to come up most often is:

function myClass() {
   this.val = 1;
}

var test = new myClass();
trace(test.val);

But this just gives me compiler errors no matter how simple I make it, and it makes no sense to me that a function could be an object. If the function is an object, where does "this" point when it is in a function in a function (that is being interpreted as an object).

Another way that seems to come up somewhat less often is:

class myClass {
   function myClass() {
       this.val = 1;
   }
}

var test = .... 

This gives me compiler errors as well, and seems more formal. But I can find very little documentation comparitivley. Most guides are either very simple, or assume that you are talking about the built in objects.

A third way that came up was to create a

 new Object();
in a function, add all the things you wanted and return it. Seems logical. But I have read all sorts of things that mention prototypes, and it seems like an object created this way would be ill suited to be a prototype. But really I am just very confused.

I also came across something saying that Object syntax was different between AS2, and AS3, but nothing more than that.

How am I supposed to create objects? What are the best practices, and for the love of god does somebody know where I can find an in depth tutorial? (my google-fu is evidently weak)

The class syntax between AS2 and AS3 is indeed different. For AS3 the syntax looks something like the following:

package somePackage {

    public class SomeClass {
        public function SomeClass() {

        }
    }
}

By way of explanation, a package is a wrapper that can contain multiple classes so you have to declare what package contains each class definition.

A class requires a constructor function. In most languages the name of the constructor function is the same as the name of the class. This is the case in ActionScript.

To call an instance of your class would look something like this:

package somePackage {

    public class OtherClass {
        public function OtherClass() {
            var something = new SomeClass();
        }
    }
}

I've got my AS3 reference sitting in front of me so I feel pretty confident with the code snippet above, but unfortunately my AS2 reference is at work but the code should look something like the following:

class ThirdClass {
    public function ThirdClass() {

    }
}

And then to instantiate a variable should look something like this:

var third = new ThirdClass();

Please not that the examples provided do not use strong typing which I would recommend using whenever possible in your ActionScript efforts.

While I would strongly recommend that you pick a copy of Essential ActionScript 2.0 and/or Essential ActionScript 3.0, I have found the following links for beginning tutorials:

Beginning Flash and ActionScript Tutorials

More Beginner Tutorials

I am from a programming background ,and newbie to flex3 . i would like to learn flex3 and develop some application using rails and flex3 . Is it necessary to know flash in order to learn flex3 or just learning Action script 3 would do ? .Can anybody tell what are the prerequisites to learn flex3 . Thanks in Advance.

You should probably learn how to use AS3, but most of the Flex learning paths I've encountered so far included both MXML and AS3.

You do not need to know anything about the Flash design tools (Flash CS3/4) to develop Flex applications.

While non-Flex applications can also be developed using Flex builder, these have nothing to do with the Flash design tool.

Summary:

Flex: Framework built on top of AS3. Use Flex Builder to develop these applications (current version is 3, the next version is going to be called Flash Builder 4 because the Adobe marketing team has to justify its existence).

Links:

AS3 - http://livedocs.adobe.com/flex/3/html/help.html?content=Part6_ProgAS_1.html

Flex - http://livedocs.adobe.com/flex/3/html/mxml_1.html#192432

Books:

Essential Actionscript 3.0 - http://www.amazon.com/Essential-ActionScript-3-0-Colin-Moock/dp/0596526946/ref=sr_1_1?ie=UTF8&s=books&qid=1250070076&sr=8-1

Programming Flex 3 - http://www.amazon.com/Programming-Flex-Comprehensive-Creating-Applications/dp/0596516215/ref=pd_sim_b_8

As for videos, the net is full of them, but since I learn much faster from books, I've never bothered to look for any videos. It does seem however that adobe has some new thing on their Developer Center. Take a look at: http://www.adobe.com/devnet/flex/learn/learningpath.html#type=role&role=programmer

The help system that comes with Flex Builder 3 is exceptionally good as well (as opposed to most other language dedicated IDEs I've encountered so far). I suggest you get a copy of FB3 and install it. Things tend to get a lot simpler once you have a working environment to experiment with, especially when the IDE offers comprehensive documentation (under the help -> help contents menu).

Good luck.

I have been working on some games in Silverlight. However, the community and portal support are still rudimentary at this point. While I expect it to improve over the next couple years, I don't plan to wait around for that.

I'm coming from a .Net heavy development background. What would you suggest I read and practice to start developing my games in Flash?

amazon.com is your friend.

Essential Actionscript

I'm a fairly experienced Web Developer. I know the LAMP stack, I can work with Javascript from a procedural level. What I'm looking for is a good resource for someone without previous Action Script experience to get his head in the game. These days for JS I usually just use jQuery and it solves most all of my UI needs. However, as time goes on, I see that I need to enhance my skill set by learning to at-least do the most rudimentary things with flash via AS3. I've worked with C, C++, Java, C# within educational settings. I know what objects are, strict typing, even generic classes, stacks, queues etc.

http://www.adobe.com/devnet/actionscript/ is not a bad starting point

If you want books then the following are good:

http://www.amazon.com/Essential-ActionScript-3-0-Colin-Moock/dp/0596526946

http://www.amazon.com/ActionScript-3-0-Cookbook-Application-Developers/dp/0596526954

There is also ActionScript Design Patterns book, which is supposed to be nice.

What are good books / site where you can learn the best practices for event driven programming in actionscript (3 obviously).

I've got a big project coming up and, to be honest, my flash is usually a big mess of classes and I don't want the the next one to turn into a ball of hair behemoth.

Colin Moock's Essential Actionscript 3.0 has a good explanation of events.

If you want free online stuff, here are some introductory articles on how AS3 Events work with the Display list:

Using Event Dispatcher is for AS2/Flash MX 2004, but is a decent introduction to the concepts of events, event dispatchers, and event listeners.

Any pointers where i could start learning flash programming. Also i would be really grateful if you could point me to place where i could get free templates for the programming

Thanks in advance

If you really want to learn Flash (as3) programming then you want to get Essential Actionscript 3 by Colin Moock.

There is a lot of AS3 code out there. You will have to be more specific regarding your goals to really provide an answer. "Flash Programming" is extremely general. Flash IDE, AS3, Flex, etc...

Hi I come from a background of 1 year of HTML/CSS/Javascript/PHP/MySQL and recently Flash based websites atracted my atention.I know that I have to learn Actionscript 3.0 and Flash program to create this type of websites but what other Technologies do I need to learn?

And also can you recomend some good books for each technology?

As @scriptocalypse mentioned Flash for general purpose sites might not be the best fit, however Flash is still widely used for Rich Internet Applications (RIAs) and games.

Most seriously development with ActionScript is done with Flash Builder which may or may not include using the Flex framework to get a jumpstart on the UI. So I'd say definitely take a look at adding Flex to your list of things to learn.

Any large scale Flash/Flex app can get pretty unwieldy without a micro-framework, Adobe has pushed Cairngorm but I personally prefer Robotlegs, there's also PureMVC which I used before Robotlegs (I prefer RL because it uses native AS3 events, as well as dependency injection which is easier to test).

Speaking of testing (which is always a good idea), there's FlexUnit and ASUnit.

If you're looking to get into game development Flixil and PushButton are popular frameworks.

The best programming book, ActionScript or otherwise, I've read is Essential ActionScript by Colin Moock. There's a RobotLegs book out there but the website docs are so good you might not need it.

I am new to AS3. I have 2 files:

main.as:

package
{
    import flash.display.*;
    public class Main extends Sprite 
    {
        public function Main()
        {
            var f0:Flower = new Flower("rose");
            var f1:Flower = new Flower("daisy");    
        }
    }
}

Flower.as:

package 
{
    public class Flower 
    {
        public var namex:String; 
        public function Flower(name:String) 
        {
            trace("Previous public var name: " + namex);
            namex = name; 
        }
    }
}

Basically, I get 2 nulls in my output. The first one I understand why; when I first trigger

var f1:Flower = new Flower("rose");

It calls the flower's function and demands a trace of a var which has not been set yet, so therefore we get a null. After the trace it sets the var with

namex = name;

which is the value string rose. but then, when I trigger the flower daisy, I am supposed(in my opinion) to receive this message: "Previous public var: rose", because when we triggered rose we told him to set public var namex to the value which we first supplied in main(rose). So why do I get 2 nulls instead of 1 null, shouldn't the other be "Previous public var: rose";

Another thing, can I get a clear explanation about what

var f1:Flower = new Flower("rose");

does exactly? does it create an object? an instance? or is it only supplying a value(rose) to the function in flower.as?

Your code:
var f1:Flower = new Flower("rose");

Creates a new instance of an object of type Flower and assigns it to the variable f1. It passes the string "rose" to the constructor function of the Flower class.

As lansen says, each instance of a Flower will have it's own namex variable with an independent value.

At this point I think it would be more productive if you take a step back and learn some fundamentals of object oriented programming rather than banging your head against something you don't have a basic understanding of. This book is a pretty good place to start: Essential ActionScript 3.0.

I am new to flash and the action scripting. I would like to start my career as a Flash Designer.

Can you please suggest, what should I do before learning Actionscripting OR the easiest way to learn actionscripting ? OR Should I needs to learn any language before learning actionscripting?

I think it is admirable that you want to learn ActionScript as a designer. I think everyone who uses Flash should know some level of ActionScript. If you want a complete overview, Colin Moock's books are outstanding: http://www.amazon.com/Essential-ActionScript-3-0-Colin-Moock/dp/0596526946

In addition he also has videos: http://www.moock.org/blog/archives/000289.html

I would advise every person who open up the program Adobe Flash to at least learn how to use the Display List and Events. Those are the two most important parts of ActionScript. That should be a good start for you.

My take on the rich internet designer / developer issue: if you want to land a position in a larger firm, where there is a clear division between designers and developers, then pick your poison, and get damn good at it.

If, on the other hand, you are going to be doing freelance work, or are going to be the interaction team of one in a small marketing department (my situation at the moment), you have little choice but pick up both roles. Honestly, I think it is much harder to function effectively in todays expansive and ever-changing climate without being a fairly strong hybrid.

To answer your question - "how do I learn actionscript": that is a big question and a deep subject, because it means you need to self-educate object oriented programming. Which is totally possible, but it will take, honestly, months of diligence.

I am a proponent of Zevan Rosser and Rich Shupe's "Learning ActionScript 3.0, cuz its what I started with. It covers all the essentials really clearly and with real-world examples. Well written and easy to follow. When you've got that under your belt, pick up Colin Mooks "Essential ActionScript 3.0 - its the definitive reference tome and is utterly comprehensive.

And the googles. Lots and lots of googles.

Last point for someone learning AS3: For the love of god, do not program on the timeline.

I'm new to AS3. Learning how to create classes. Is comp = new HouseObjects creating a new class? Is comp creating an instance of the HouseObjects? I realize that this is inside public class TreeHouse. I'm thinking that HouseObjects, how I set it up is not a class...not sure what the correct way to set up classes and properties.

Also I noticed, that when I tried to link another movieclip using the same linkage name HouseObjects--it asked to enter a unique class. I'm trying to create multiple instances from the same class called HouseObjects.

alt text

package {

 import flash.display.MovieClip;
 import flash.events.MouseEvent;
 import flash.events.Event;

 public class TreeHouse extends MovieClip

 {

private var comp:MovieClip;
var powerData:int; // stores user data (of selected data)
//var currentPower:int; // stores current power

public function TreeHouse()
{
    comp = new HouseObjects; // linkage in library
    comp.power = 2; // amount of power
    comp.name = "comp";
    comp.buttonMode = true;
        comp.bstate = 0; // button state


    //add event listeners -- listens to functions that are called       
   comp.addEventListener(MouseEvent.MOUSE_OVER, rolloverToggle);
   comp.addEventListener(MouseEvent.MOUSE_OUT, rolloutToggle);
   comp.addEventListener(MouseEvent.CLICK, toggleClick);
   comp.addEventListener(MouseEvent.CLICK, toggleClick);

  stage.addChild(comp); // add computer to stage -----------------------------------
  trace("tracing...");
  comp.x = 100;
  comp.y = 100;

} 

// function rollOver -------------------------------------------------------------- 
function rolloverToggle(e:MouseEvent) {     
    if (e.currentTarget.currentFrame == 1)
    e.currentTarget.gotoAndStop(2);
   if (e.currentTarget.currentFrame == 3)
    e.currentTarget.gotoAndStop(4);
}

// function rollOut-- --------------------------------------------------------------    
function rolloutToggle(e:MouseEvent) {
    if (e.currentTarget.currentFrame == 2)
    e.currentTarget.gotoAndStop(1);
    if (e.currentTarget.currentFrame == 4)
    e.currentTarget.gotoAndStop(3); 
}

// function toggleClick-------------------------------------------------------------
   function toggleClick(e:MouseEvent) {


  // On MouseEvent gotoAndStop(Frame Number)
  if (e.currentTarget.currentFrame == 2)
   {
    e.currentTarget.gotoAndStop(3);
    e.currentTarget.bstate = 1;
   }

   if (e.currentTarget.currentFrame == 4)
   {
    e.currentTarget.gotoAndStop(1);
    e.currentTarget.bstate = 0;
   }     

 //var powerData:int = HouseObjects[e.currentTarget.power]; // set power value  

  // Find out which object selected-------------------------------------------------
  //trace("movieClip Instance Name = " + e.currentTarget); // [object Comp]
  //trace(houseArray[e.currentTarget.name]); // comp
  trace("using currentTarget: " + e.currentTarget.name); // comp
  //trace("powerData: " + powerData); // power of user data
  //trace("houseArray: " + houseArray[0]); // the 0 index of house array
  trace(e.currentTarget.power); // currentTarget's power************ 


   }

 } //end of class

} // end of package

If you are new to AS3, and OOP in particular, you should check out Moock's Essential Actionscript 3 which is beyond fantastic for a step by step education in OOP in AS3.

HouseObjects appears to be a class and you are creating a new instance of it for the variable comp

You've got a duplicate definition. It appears that you are trying to use Flash Pro to extend HouseObjects for the lightbulb. It doesn't work like this in Flash Pro. You are creating a MovieClip symbol and giving it a class definition. It has to extend MovieClip and you cannot change this in this case. You could likely extend HouseObjects in an AS3 file and make use of it in your application.

Personally think that if you want to really get your head around OOP with AS3 you should get the book and get out of Flash Pro. Use an IDE like Flash Builder, FDT, Flash Develop, or IntelliJ IDEA. It is a lot easier to understand when you get away from the dialogs and other complications of the Flash Pro IDE :>

I'm wanting to change my movie clips to actionscript classes in AS3. Is there a standard list of things I need to do to make sure the classes work?

Check out these resources:

Grant Skinners Introductory AS3 Workshop slidedeck http://gskinner.com/talks/as3workshop/

Lee Brimelow : 6 Reasons to learn ActionScript 3 http://www.adobe.com/devnet/actionscript/articles/six_reasons_as3.html

Colin Moock : Essential ActionScript 3 (considered the "bible" for ActionScript developers): http://www.amazon.com/Essential-ActionScript-3-0/dp/0596526946

mike chambers

mesh@adobe.com

I've got in over my head trying to learn programming, but love it. How would you teach a designer to migrate from design to object oriented programming?

My interest is AS3 in Flash IDE, but any advice is welcome. Looking for a full explanation.

THOUGHTS
Designers learn differently
Designers may need visual cues
Designers may have different working habits, some bad, some just different

I suggest to go ahead with "Learning Actionscript 3" by O'Reily. It is a very useful book that guides you step-by-step throughout the process of learning AS3. For instance, it will show you how to directly code a textbox, without having to create it using the textbox tool itself. Plus, there are a lot of example codes on the website, as well as quizzes to help you "revise" the material.

I do recommend another book, entitled "Actionscript 3.0 Bible", which can be used as a reference guide in case you ever forget anything, or even as a learning guide that covers almost everything.

Check out this list of learning tools for AS3. Might be useful.

If your interest lies in AS3 then I would highly suggest Essential Actionscript 3.0 by Colin Moock. It's an excellent resource for learning AS3/OOP. It also serves as an excellent reference once your comfortable writing general code.

As for learning your way around the Flash IDE, practice is going to be the best approach, but I might also suggest Lynda.com. Good luck!

I was just asked to revamp all of the training which uses action script. Anyone have a good recommendation for a book or site that will provide a decent crash course with Adobe Action Script?

To be honest, I have no experience in flash. So if anyone can point me to the necessary direction. That would be great. I was tasked to build a countdown timer with all the features that can be found on http://www.online-stopwatch.com/ You might argue that why don't I use the one found in the link I provided but I was tasked to create a personalized one with background and layout that will be completely different from the one in the link.

I've looked at some tutorials but none can point me to the direction that's needed. Thank you for the help.

This is not really a question that can be answered in one answer, its more like you need to completely learn action-script 3.0 and then use that knowledge to write this program. Here is a link to a book that i found great for learning action-script 3.0 and flash in general. IF you don't want to learn everything about action-script 3.0 then consider looking up tutorials on the basics of it and then specifically on the Timer Class. If you want a good program that has everything that the website you cited has, then you should probably just read the Essential Actin script 3 book, but if your pressed for time you can quickly learn the basics and try and throw something together, but it won't be very good.