Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 01-09-2003, 03:51 AM   #1
carlhusic
Registered User
 
Join Date: Dec 2002
Location: Scottsdale, AZ
Posts: 22
Unhappy creating functions (methods) for a movie clip?

I'm using Flash 5 (not up to MX yet)

I've created a movie clip that I want to show and hide (using
movement and alpha fades) when certain buttons are pressed.

The "show" runs one portion of the clip containing a motion
tween that moves it onto the visible part of the movie and fades
the alpha to 100% until it hits a keyframe with stop() in it. The
"hide" runs another portion that does the reverse.

The control buttons (external to the movie clip) have the
appropriate gotoAndRun(framenum) calls in them, and they work
just fine to make the clip do it's thing.

In the spirit OOP, I'd like to create functions attached to the clip
(called "showMe()" and "hideMe()") so that I could change the
internals of the clip without the button needing to worry about
it. Basically the button code would look like:

on(press) {
_root.someClip.showMe();
}

So the question is - can I create functions like this? The movie
explorer seems to let me create functions on a movie clip instance
(using the "function") but for some reason, they seem to
disappear if I close the movie explorer and then go back to find
them!

Basically I'm treating the clips as objects and trying to make some
new methods for them. Is this possible at all? The follow up
question is, (if the answer to the above is true) is it possible to
attach functions/methods to the library object instead of the
instance in the movie, kind of like when you define methods when
you define a class in Java or C++?

If these things are not possible in Flash 5, how about MX?
carlhusic is offline   Reply With Quote
Old 01-09-2003, 08:11 AM   #2
jimburton
no sleep til bedtime
 
jimburton's Avatar
 
Join Date: May 2001
Location: Brighton
Posts: 1,322
Default

you are on theright track - a function is a method of a particular object if it is defined within the scope of that object - for movieclips think of defining the function on the movieclip's timeline...so if you were to double-click on a clip to go into it's timeline, open the actions panel and type:
ActionScript Code:
function sayHi() { trace("hi!"); }
then you could call myClip.sayHi();

the other way to do it (which works fine in f5) is to define it from the main timeline, by going:
ActionScript Code:
myClip.sayHi = function () { trace("hi!"); }
which has the same effect....or you could add this method to every movieclip in the movie by adding to the movieclip prototype:
ActionScript Code:
movieclip.prototype.sayMyName = function () { trace(this._name); }

the bit that mx adds on to this is that you can define event handlers (onpress etc) like any other function, from any scope, and remove them too. there is a really good intro to oop in flash which covers timelines and scope at
robin debreiul's site
jimburton is offline   Reply With Quote
Old 01-09-2003, 09:04 AM   #3
farafiro
Addicted To FLASH
 
farafiro's Avatar
 
Join Date: Dec 2001
Location: Egyptian in UAE
Posts: 12,436
Send a message via MSN to farafiro Send a message via Yahoo to farafiro
Default

check the function here also

http://moock.org/asdg/technotes/
__________________
‚€* GOD Is Near ‚€*
Questions Don't PM for Questions . Thanks
An eye for an eye, make the whole world blind
_____________________________________________GHANDI
farafiro is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:27 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.