A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: class problems

Hybrid View

  1. #1
    PlayerForever adi4x's Avatar
    Join Date
    Feb 2005
    Posts
    753

    Cool class problems

    I'm moving to as3 now after 5 yrs as2
    .. this may be very simple for you.


    I have myMenu.as class working well as a Document Class

    When i try to make it work like an included class
    Code:
    myMenu()
    Is this correct ???

    with no document class i have the next error
    Code:
    Scene 1, Layer 'Actions', Frame 1, Line 1	1136: Incorrect number of arguments.  Expected 1.
    But the function has no argument needed

    Code:
    public function myMenu(){
    //bla bla
    }
    Card Games - play many card games free
    Free Games many free online games

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    If you are trying to create a new instance of myMenu, then you need the "new" keyword:
    Code:
    var aMenu:myMenu = new myMenu();
    If that's not what you're trying to do, I don't know what you're trying to do. But
    Code:
    myMenu(somevalue);
    is the syntax for casting somevalue to myMenu. That is probably what the compiler thinks you're trying to do, which is why it expects an argument. But you're not trying to do that anyway.

  3. #3
    PlayerForever adi4x's Avatar
    Join Date
    Feb 2005
    Posts
    753
    no. I have a class for the right click menu.

    Works great as a document class. How can i use it in a fla ? if i "run" the constructor i have this error
    1136: Incorrect number of arguments. Expected 1.
    Attached Files Attached Files
    Last edited by adi4x; 10-28-2011 at 03:15 PM.
    Card Games - play many card games free
    Free Games many free online games

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    "no"? What are you saying no to?

    You are not "running" the constructor with the code you posted above. You are incorrectly attempting to cast an empty argument list to myMenu. That's not what you want. If you want to create a new instance of myMenu, you need to use the "new" keyword.

    It doesn't even make sense to "run" a constructor. What do you think that means? Post the code where you are attempting to do that.

  5. #5
    PlayerForever adi4x's Avatar
    Join Date
    Feb 2005
    Posts
    753
    ( i was just posting it.. you answered while i was typing)

    This file if used as DOCUMENT class is supposed to pop a CUSTOM right click menu!
    But i want to use it as a file normal class.. because i want to make many others... and i have that error.
    Card Games - play many card games free
    Free Games many free online games

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You still haven't posted the code where you are attempting to "run" the constructor, or what you think that means.

  7. #7
    PlayerForever adi4x's Avatar
    Join Date
    Feb 2005
    Posts
    753
    its attached UP here
    Card Games - play many card games free
    Free Games many free online games

  8. #8
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    No, that is myMenu.as. I am asking for the code where you attempt to "run" the constructor. I am also asking you to explain what you think "run the constructor" means.

  9. #9
    PlayerForever adi4x's Avatar
    Join Date
    Feb 2005
    Posts
    753
    I place this in the first line of the first frame of the FLA
    myMenu()
    Card Games - play many card games free
    Free Games many free online games

  10. #10
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I have already explained why that doesn't work: it does not call the constructor of myMenu. It attempts to cast nothing to myMenu, which is why you get the error about expecting an argument.

    Even if it DID call the constructor, what would you expect to happen? You aren't doing anything with the new instance of myMenu.

  11. #11
    PlayerForever adi4x's Avatar
    Join Date
    Feb 2005
    Posts
    753
    .. well..

    I just want a right click menu. What should i use in the main Flash file > game.fla ?
    Card Games - play many card games free
    Free Games many free online games

  12. #12
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Well, you could make your document class be or extend myMenu, but myMenu doesn't seem to do much besides configure a ContextMenu with hardcoded values.
    Or, you could do the same things myMenu does directly in your document class.
    Or, you could change myMenu to have static functions which add and configure a context menu on an instance that you pass in (though I do not like this approach, it's not particularly object oriented style).

  13. #13
    PlayerForever adi4x's Avatar
    Join Date
    Feb 2005
    Posts
    753
    Quote Originally Posted by 5TonsOfFlax View Post
    Well, you could make your document class be or extend myMenu, .
    How to make it to extend the document class? I think this is what I'm looking for.

    I just want to apply the myMenu class to each new fla I make without making myMenu class as Document Class
    Card Games - play many card games free
    Free Games many free online games

  14. #14
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You don't want myMenu to extend the document class, you want the document class to extend myMenu. That is, you want your new class to be a myMenu as well as whatever new stuff you add.

    To do that, simply add "extends myMenu" to the class declaration, just like you made myMenu extend MovieClip:
    Code:
    public class Something extends myMenu {
    By the way, by convention, classes begin with a capital letter and variables begin with a lower case letter.

  15. #15
    PlayerForever adi4x's Avatar
    Join Date
    Feb 2005
    Posts
    753
    It seems like I have to practice a lot more before i start to code again
    Thanks a lot for your support!
    Card Games - play many card games free
    Free Games many free online games

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