Calling a method in another class
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Calling a method in another class

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    26

    Question Calling a method in another class

    I am new to AS3. I am creating a series of Flash Activities for an educational website and would like to put common function into their own class. I am not sure how to do that. What is have tried is:

    1. Import the class( import MMESCommon
    2. creating a new variable/object(var MMES:Object = new MMESCommon
    3. Calling a function in the class(MMES.LetterScore(95)

    This process( or one very similar) has worked for me in other languages. However, here I am getting the error:

    ReferenceError: Error #1069: Property LetterScore not found on MMESCommon and there is no default value.
    at AdditionLevel01/DrawGameFrame()
    at AdditionLevel01/checkanswer()

    I know LetterScore exists. here in the MMES Class:
    Code:
    /**
     * Mrs. Marker's Education Site Common Flash funcions
     * This file contains the action script for the MMES Common class.
     * AS3
     * MMES(tm) : Mrs. Marker's Educational Site (http://mrsmarker.dyndns.org)
     * Copyright 2012, Mrs. Marker's Educational Site (http://mrsmarker.dyndns.org)
     * @copyright     Mrs. Marker's Eduational Site (http://mrsmarker.dyndns.org)
     * @link          http://mrsmarker.dyndns.org MMES(tm)
     * @package       MMESCommon
     * @license       Propietary, All Rights Reserved
     */
    package {
    	/**
    	 * Global import commands
    	 */
    	import flash.display.*;
    	import flash.events.*;
    	/**
    	 * MMESCommon Class definition
    	 * This class contains methods used by some/all of the MMES Flash Programs
    	 * @extends MovieClip
    	 */
    	public class MMESCommon extends MovieClip {
    		/**
    		 * LetterScore function
    		 * Funtion to take numberal score and return a letter grade.
    		 * @param	score
    		 * @return  String: The letter grade earned
    		 */
    		public function LetterScore(score:int):String {
    			var retval:String = "";
    			if (score >= 90 && score <= 100) {
    				retval = "A";
    			} else if (score >= 80 && score <= 89) {
    				retval = "B";
    			} else if (score >= 70 && score <= 79) {
    				retval = "C";
    			} else if (score >= 60 && score <= 69) {
    				retval = "D";
    			} else if (score >= 50 && score <= 59) {
    				retval = "F";
    			} else {
    				retval = '--';
    			}
    			return retval;
    		}
    	}
    }
    What could I be doing wrong? Thanks for any help, Troy

  2. #2
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    666
    public function LetterScore -> public static function LetterScore ?

    edit: wait, I thought you were doing MMESCommon.LetterScore(95)
    Last edited by realMakc; 02-07-2013 at 05:10 AM.

  3. #3
    FK Romeo martiansam's Avatar
    Join Date
    Oct 2001
    Location
    Bombay, India
    Posts
    223
    Try:

    var MMES:MMESCommon = new MMESCommon() ;
    MMES.LetterScore(95) ;

    Actually will have to see your class structure to debug it. Alternatively, you can make it a static class if that works for your structure.
    sameer rao

    there...you see!!

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

Poll by Flashkit.com