A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: assigning methods to objects in a class

  1. #1
    flash fiend
    Join Date
    Dec 2000
    Location
    Bellingham, WA
    Posts
    63

    assigning methods to objects in a class

    I'm just now getting into writing classes and I want to make sure I'm not going down the wrong path with declaring my methods as "static". So, the class is used to create dropdown items, and my area of concern is where I declare the OnRollOver and OnRollOut functions. In the following exampe the only way I could trigger the assigned methods was to define the methods as "static", and include the name of the class in the path: "Dropdown.createLineItems(this._parent);". It works, but I imagine there are other ways to go about this. Any suggestions?



    class Dropdown {
    private var clip:MovieClip;
    private var depth:Number;
    private var mouseListener:Object = new Object();
    private static var SYMBOL_ID:String = "dropdown_pw_proto";
    //--
    public function Dropdown(target:MovieClip, x:Number, y:Number) {
    depth = target.getNextHighestDepth();
    clip = target.attachMovie(Dropdown.SYMBOL_ID, "dropdown_pw"+depth, depth);
    clip._x = x;
    clip._y = y;
    clip.lineitem_proto._visible = false;
    clip.top.useHandCursor = false;
    clip.top.onRollOver = function() {
    trace(this);
    Dropdown.createLineItems(this._parent);
    };
    clip.top.onRollOut = function() {
    trace(this);
    Dropdown.removeLineItems(this._parent);
    };
    }
    //--
    private static function createLineItems(clip):Void {
    trace("create lines "+clip);
    clip.gotoAndStop(2);
    var x:Number = 0;
    for (x=0; x<5; x++) {
    duplicateMovieClip(clip.lineitems.lineitem_proto, "lineitem"+x, clip.lineitems.getNextHighestDepth());
    var mylineitem:MovieClip = clip.lineitems["lineitem"+x];
    mylineitem._y = mylineitem._height*x;
    }
    }
    //--
    private static function removeLineItems(clip) {
    //trace("remove function"+clip);
    clip.gotoAndStop(1);
    //Mouse.removeListener(Dropdown.mouseListener);
    }
    }
    My flash never has bugs, it just develops random features.

  2. #2
    FK Slacker
    Join Date
    Jun 2000
    Location
    vancouver
    Posts
    3,208
    A better way is to use the Delegate class:

    code:

    clip.top.onRollOver = mx.utils.Delegate.create(this,createLineItems);
    clip.top.onRollOut = mx.utils.Delegate.create(this,removeLineItems);



    This will redirect the scope of the function calls back to the class, eliminating the need to make static methods...

    K.

  3. #3
    flash fiend
    Join Date
    Dec 2000
    Location
    Bellingham, WA
    Posts
    63
    nice! thanks a ton
    My flash never has bugs, it just develops random features.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center