Categories
Flash

More Casting Calls for Dummies

From the very basic Flash Class…

In flash everything is an object, buttons, MovieClips, text boxes.
Objects are built from blueprints called Classes
Classes have properties and methods (or functions)

Flash needs to know what classes the object is associated with

Objects are built from Classes so I (Mark) am built from the Man class

I’m also built from these other classes
Vermonter
Armenian
ComicBookGeek
Dad

So I can do all the things involved with this like, garden,eatBaklava, washDishes, readComics, helpWithHomework, cook, doWash

These are the equivalent of flash’s _mc.gotoAndStop, _mc.play() _mc.stop().

With the main timeline it is a container that holds all of our display objects, Flash needs to be told how to think of it

So on Sundays, having been busy with my many responsibilities, I have to be told to think like a man

Man(Mark).watchFootball()
Man(Mark).drinkBeer()
Man(Mark).burp()

This is called casting to class.

So to get flash ‘s main timeline or root t thinklike a movieclip we need to say

MovieClip(root).gotoAndStop(“end”)

2 replies on “More Casting Calls for Dummies”

Hi Mark,

Hmmm, I don’t quite follow why you have to cast your Mark instance as different types. Doesn’t the Mark instance inherit all the methods of all those classes by default?

Can you do multiple inheritance in CS3?

Can’t do multiple inheritance in CS3

In this case, it comes from wanting to use root on a movie clips timeline to control where you go in the movie’s main timeline. Old school I know.

With other objects then root your right it would inherit the methods and yes I would use composition to create a Mark object but this is for a beginning Flash class, they don’t need to know this stuff. Heck they won’t even remember this. One out of 20 is even going to ask this question, why am I even bothering?

anyways…

Root no longer allows access to MovieClip methods because it’s a display object, allthough I’m pretty sure it will return true if you ask Flash if it’s a Movie Clip.

You don’t have to even cast it as a Movie Clip just stick it in a variable to access the methods, but I thought it was better to show it as casting for a beginning class so they could see what was going on.

If you want references to it in a class you have to pass it in as a parameter to the class. It means AS3 dumps lockroot.

Leave a Reply to Ed Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.