• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Help Getting Started w/Classes

Explorer ,
Jun 01, 2012 Jun 01, 2012

Copy link to clipboard

Copied

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.

TOPICS
ActionScript

Views

878

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 01, 2012 Jun 01, 2012

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:Number):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

Votes

Translate

Translate
Community Expert ,
Jun 01, 2012 Jun 01, 2012

Copy link to clipboard

Copied

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:Number):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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 01, 2012 Jun 01, 2012

Copy link to clipboard

Copied

import PFarmFunctions;

var obj:PFarmFunctions=new PFarmFunctions();

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 01, 2012 Jun 01, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 01, 2012 Jun 01, 2012

Copy link to clipboard

Copied

Thanks much, I think on my way.

kglad: Extra thanks for being thorough and cleaning up my code - really appreciate it

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 01, 2012 Jun 01, 2012

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines