oop with actionscript in flash

about 5 years ago malczak actionscript comments

currently im developing some code using actionscript 2 in flash 8. so ive implemented a class lets say

code 1:

 1 class myclass extends MovieClip {
 2   public function myclass(){
 3     trace("myclass - constructor"); 
 4   }
 5   private function onLoad() :Void 
 6   { 
 7     trace("On Load from class"); 
 8   }
 9 }
10 
11 class myclass extends MovieClip {
12 
13    public function myclass()
14    {
15      trace("myclass - constructor");
16    };
17 
18    private function onLoad() :Void
19    {
20       trace("On Load from class");
21    };
22 
23 }

in flash ive linked that class with some movie clip (this is the way you can extend movie clips in flash ;)). after putting clip on stage ive added it an action

code 2:

1 onClipEvent (load) {
2     trace("loading from IDE");
3 }

and while running this script we can see that : I. code defined for object already placed on stage does not override function defined in class implementation ( that is both - code 1 and code 2 will be invoked ) II. code 2 will be invoked as the first one afterwards code 1

-- a friend of mine said : "well, its normal behavior ! didnt you know that ?!?" ;/

i didnt ...

BUT... lets suppose ive placed my object in first frame and called it : tst. if i write, also in first frame, code shown as code 3 i will override onLoad function defined in class implementation. and new onLoad handler will also be invoked after code 2:

code 3:

1 tst.onLoad = function()
2 { 
3   trace("OnLoad from IDE - onLoad
4 
5 
6 <p>-
7 i think that what flash do is that it treads onClipEvent as if it was method implemented for MovieClip. in my class, MovieClips descendant, flash modifies onLoad method adding <code>super.onLoad()</code> code. this tip works also for other events that can movieclip handle.</p>

Comments

No comments as yet. Be first to comment.

New comment

  1. (with http or https prefix)

  2. (use [code][/code] tags to post a code snippet)

  3. (javascript is required)

Website content premeditately commited by malczak & sobstel.
Layout by mlando. Icons by dryicons.com. All rights reserved.