A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Class's movieclip calling a function in it's own class

Hybrid View

  1. #1
    Junior Member
    Join Date
    Feb 2007
    Posts
    7

    Class's movieclip calling a function in it's own class

    For the life of me I can't find an internet source that explains why this doesn't work. I know it's a scope problem but I know no other way around it and there must be a way to do it, I'm thinking.

    I have a class. Inside this class I create a movieclip which I have a class variable link to. The movieclip is created on _root. When I click on this movieclip, I want it to call a function inside the class. Here's what it looks like.

    Code:
    class Whatever extends Movieclip {
      private var mc:MovieClip;
    
      public function Whatever() {
        this.mc = _root.createEmptyMovieClip("rootmc",_root.getNextHighestDepth());
        [code for drawing a square]
        this.mc.onPress = this.doSomething();
      }
    
      public function doSomething {
        [do something]
      }
    In the above sample, when I click on the movieclip, the "doSomething" function is not called, obviously because the movieclip is on root and has nothing to do with the class. Is there a way to do what I want to do?

  2. #2
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    umm if this is what i think it is, usually the following will "fix" it:

    class Whatever extends Movieclip {
    private var mc:MovieClip;

    public function Whatever() {
    thisClass = this;
    this.mc = _root.createEmptyMovieClip("rootmc",_root.getNextH ighestDepth());
    [code for drawing a square]
    this.mc.onPress = thisClass.doSomething();
    }

    public function doSomething {
    [do something]
    }

    try it and see if that does the trick
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  3. #3
    Junior Member
    Join Date
    Feb 2007
    Posts
    7
    No, that doesn't seem to work. It gives me an error that the property doesn't exist so I do

    var thisClass = this;

    instead, and then it accepts it but does not work. Maybe I need to rethink what I am doing.

  4. #4
    Junior Member
    Join Date
    Feb 2007
    Posts
    7
    Nevermind, that actually did work. Thank you very much.

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