A Flash Developer Resource Site

Results 1 to 19 of 19

Thread: custom Class won't recognize onRollOver

  1. #1
    Keeper of Brooms and Jars
    Join Date
    Oct 2001
    Posts
    456

    custom Class won't recognize onRollOver

    I created a custom Class for my menu items so I can manage them easily. The only problem is I want to use, among other things, the onRollOver clip event, but it won't work! I know there is a way to sort of duplicate the MovieClip class (basically copying movie's prototype into my class's, which would allow my class access to the onRollOver event) but I can't for the life of me figure out how. I also think there is a way to make my class a subclass of the movieclip class, but, once again, my memory fails me. I seem to remember something about __proto__ but all my efforts have ended in failure. Can someone help me out?
    *smiles, waves*

  2. #2
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    well, what are you using now?

  3. #3
    Keeper of Brooms and Jars
    Join Date
    Oct 2001
    Posts
    456
    Nothing. I'm stuck. I've come to realize that in using something like
    Code:
    myClass.prototype.__proto__=MovieClip.protoype;
    the objects of myClass only have access to methods and properties in MovieClip.prototype (which does not include events such as onRollOver). In that case, it seems that the only option would be to modify the MovieClip class itself and add my own custom methods, which would not only get nasty but most likely end up causing more problems that it solves. My next thought would be to copy the entire MovieClip class - methods, properties, events etc. But I don't know if this is possible and have not been able to work it out as of yet. Any thoughts or suggestions at all are welcome. Thanks for your time.
    *smiles, waves*

  4. #4
    Retired SCORM Guru PAlexC's Avatar
    Join Date
    Nov 2000
    Location
    NJ
    Posts
    1,387
    Ah, simple syntax error.

    myClass.prototype = new MovieClip();

    You can then prototype what you wnat to happen on movie clip methods and events by doing:

    myClass.prototype.onRollOver = function () {
    // do your rollover stuff here
    }
    Last edited by PAlexC; 06-04-2003 at 02:14 PM.
    "What really bugs me is that my mom had the audacity to call Flash Kit a bunch of 'inept jack-asses'." - sk8Krog
    ...and now I have tape all over my face.

  5. #5
    Keeper of Brooms and Jars
    Join Date
    Oct 2001
    Posts
    456
    !! thanks dude, i knew there was a simple way to do it.
    *smiles, waves*

  6. #6
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    myClass.prototype.__proto__=MovieClip.protoype;

    still sets inheritance, it just breaks super() (and isnt recomended as a standard). The super you can get back easy enough, but I think the reasoning isnt quite just about that kind of inheritance...

    how are you handling your actual menu items?

    [edit] then again maybe not [/edit]

  7. #7
    Retired SCORM Guru PAlexC's Avatar
    Join Date
    Nov 2000
    Location
    NJ
    Posts
    1,387
    You did register your menu item as myClass, right?

    Object.registerClass("mymenuitemlinkagename",myCla ss);

    If your menu item is a MC to begin with, the MC properties and methods should stick with it, but it can't hurt to re-apply the prototype.
    "What really bugs me is that my mom had the audacity to call Flash Kit a bunch of 'inept jack-asses'." - sk8Krog
    ...and now I have tape all over my face.

  8. #8
    Keeper of Brooms and Jars
    Join Date
    Oct 2001
    Posts
    456
    im not sure if im going to physically place them on the stage before runtime and use a loop to make them objects of my menuItem class, or if ill use registerClass and attachMovie. at this point im not sure if registerClass/attachMovie would be practical for 5 or so items.. there is something to be said of the balance between complexity and practicality
    *smiles, waves*

  9. #9
    Retired SCORM Guru PAlexC's Avatar
    Join Date
    Nov 2000
    Location
    NJ
    Posts
    1,387
    If you use registerClass, everything will work fine as long as you add those items to a frame on the timeline that comes AFTER you've done the actionscript.
    "What really bugs me is that my mom had the audacity to call Flash Kit a bunch of 'inept jack-asses'." - sk8Krog
    ...and now I have tape all over my face.

  10. #10
    Keeper of Brooms and Jars
    Join Date
    Oct 2001
    Posts
    456
    no i didnt use registerClass (in my above posts) because i only had one item that i was trying to get to cooperate with this new class. i used item=new MenuItem(); where 'item' is the object that becomes the object of the new class and menuItem is the new class.. (for those of you new to OOP - http://www.debreuil.com/docs/ch01_Intro.htm - awesome stuff)
    *smiles, waves*

  11. #11
    Keeper of Brooms and Jars
    Join Date
    Oct 2001
    Posts
    456
    senocular - im still fuzzy on super() and a few other fairly large aspects of the whole deal... need to go back and read the last few chapters of that tute again :-D
    *smiles, waves*

  12. #12
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    well using the __proto__ way, heres what you'd do:

    Code:
    myClass = function(){}
    myClass.prototype.__proto__ = MovieClip.prototype;
    myClass.prototype.onRollOver = function(){
    	trace("RolledOver");
    }
    
    menuItem_mc.__proto__ = myClass.prototype;
    So long as you set all the __proto__'s of your menuitem clips to reference the myClass prototype, they'll recognize the onRollover. Since you are referening the mc directly, though, it will have to exist before __proto__ can be set like that (obviously);

    For the standard method, you would need to do something like this (based on what PAlexC mentioned):
    Code:
    myClass = function(){}
    myClass.prototype = new MovieClip();
    myClass.prototype.onRollOver = function(){
    	trace("RolledOver");
    }
    Object.registerClass("mymenuitemlinkagename", myClass);
    // some frame after this, they can appear either via the
    // timeline or by being attached with attachMovie
    And FYI, Robins OOP explainations (from that link) are Flash 5
    Last edited by senocular; 06-04-2003 at 03:19 PM.

  13. #13
    Keeper of Brooms and Jars
    Join Date
    Oct 2001
    Posts
    456
    thanks that clears a few things up. yeah i know thats flash 5, but its the best set of articles ive been able to locate about OOP (granted i havent done much looking since i found them). are there any comparable MX articles floating around?
    *smiles, waves*

  14. #14
    Retired SCORM Guru PAlexC's Avatar
    Join Date
    Nov 2000
    Location
    NJ
    Posts
    1,387
    I just stick to registerClass b/c I find it easier when reading through code to see my linkage name and class name next to each other.

    I don't think there's much of an advantage either way, is there?
    "What really bugs me is that my mom had the audacity to call Flash Kit a bunch of 'inept jack-asses'." - sk8Krog
    ...and now I have tape all over my face.

  15. #15
    Keeper of Brooms and Jars
    Join Date
    Oct 2001
    Posts
    456
    I don't know but I've run into a little problem that I don't understand. Heres what my code looks like:
    Code:
    MenuItem = function(){}
    MenuItem.__proto__ = MovieClip.prototype();
    MenuItem.prototype.onRollOver = function(){
            //for example
    	this.gotoAndStop(2);
    }
    //this is the item that is already on the stage
    menu.item1.__proto__=MenuItem.prototype;
    so menu.item1 is supposed to gotoAndStop(2) when its rolledOver... the little white hand appears when i rollOver, and if i try a trace everything works fine, but the gotoAndStop doesnt. i have a feeling im not referencing the item correctly (as in 'this'). can anyone see the problem?
    *smiles, waves*

  16. #16
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    for MX? None as good as that one. I have a few explainations floating around here and there about different things. Lets see what I can find:

    The comments here discuss some inheritance starting with like comment 5 or 6:
    http://proto.layer51.com/d.aspx?f=604

    This goes into a little of the differences of objects and movieClips
    http://www.actionscript.org/forums/s...threadid=28896

    two threads about super:
    http://forums.ultrashock.com/forums/...&threadid=2118
    http://www.actionscript.org/forums/s...threadid=28710

    Some dilly-dallying in an inheritance proposal (fla included)
    http://www.actionscript.org/forums/s...threadid=26314

  17. #17
    Keeper of Brooms and Jars
    Join Date
    Oct 2001
    Posts
    456
    merci
    *smiles, waves*

  18. #18
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    Originally posted by pkghost
    I don't know but I've run into a little problem that I don't understand. Heres what my code looks like:
    Code:
    MenuItem = function(){}
    MenuItem.__proto__ = MovieClip.prototype();
    MenuItem.prototype.onRollOver = function(){
            //for example
    	this.gotoAndStop(2);
    }
    //this is the item that is already on the stage
    menu.item1.__proto__=MenuItem.prototype;
    so menu.item1 is supposed to gotoAndStop(2) when its rolledOver... the little white hand appears when i rollOver, and if i try a trace everything works fine, but the gotoAndStop doesnt. i have a feeling im not referencing the item correctly (as in 'this'). can anyone see the problem?
    two typos, one from you, one from me

    MenuItem.__proto__ = MovieClip.prototype();

    should be

    MenuItem.prototype.__proto__ = MovieClip.prototype;

  19. #19
    Keeper of Brooms and Jars
    Join Date
    Oct 2001
    Posts
    456
    i was going to ask you why your code was without the .prototype and Robin's included it... thanks much
    *smiles, waves*

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