Skip navigation
Currently Being Moderated

Help Getting Started w/Classes

Jun 1, 2012 9:18 AM

Hi:

I'd like to setup a class file to store functions that I use frequently, not sure how to do it, but I think I'm close.  Here's a simple example that doesn't quite work, I get error:

 

import PFarmFunctions;

PFarmFunctions.fadeMe (mc,"off",1,1);

 

Call to a possibly undefined method fadeMe through a reference with static type Class.

 

My code is:

package {

import com.greensock.*;

import com.greensock.easing.*;

import com.greensock.plugins.*;

 

import fl.events.*;

 

import flash.display.DisplayObject;

import flash.display.MovieClip;

import flash.events.Event;

import flash.display.Sprite;

 

public class PFarmFunctions {

private var who:Object;

private var onOff:String;

private var delayTime:Number;

 

public function fadeMe(who:Object, onOff:String, howLong:Number, delayTime:Number):void {

if (onOff == 'off') TweenMax.to(who, howLong,{autoAlpha:0,delay:delayTime});

}; //End fadeMe

}

 

}

If someone could help me get going on this, I'd appreciate it very much.

Thanks.

 
Replies
  • kglad
    72,322 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 1, 2012 10:41 AM   in reply to voxL

    use public static functions (and use a shorter class name).  for example:

     

    package{

    // import statements

    public class R{

    public static function fadeMe(dobj:DisplayObject,duration:Number,delayNum:Number,inOut:Numbe r):void{

    TweenMax.to(dobj,duration,{autoAlpha:inOut,delay:delayNum});

    }

    // etc

    }

    }

     

    then to use, in any of your classes:

     

    R.fadeMe(mc,1,2,0);  // where mc is a display object you want to fade out over 1 second with a 2 second delay

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 1, 2012 11:33 AM   in reply to voxL

    import PFarmFunctions;

    var obj:PFarmFunctions=new PFarmFunctions();

     

    obj.fadeMe (mc,"off",1,1);

     
    |
    Mark as:
  • kglad
    72,322 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 1, 2012 2:55 PM   in reply to voxL

    don't use the code suggested by esdebon unless you change PFarmFunctions into a singleton class.

     
    |
    Mark as:
  • kglad
    72,322 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 1, 2012 9:34 PM   in reply to voxL

    you're welcome.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points