A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: AS3 & Class' simple issue

  1. #1
    Senior Member
    Join Date
    May 2002
    Posts
    359

    AS3 & Class' simple issue

    ARRGHH! im pulling my hair out!!!


    im new to as3 and classes, i cant seem to get the following to work:

    my .as code is called Doorman.as and is saved in the root directory with my .fla document.
    Code:
    package{
    	public class Doorman{
    			
    
    			
    			public function walk(characterDirection:String):String{
    				if (characterDirection == "forward"){ 
    					trace(characterDirection);
    				}
    				
    			}
    	}
    }

    my .fla document looks like this:

    Code:
    import Doorman;
    
    
    
    var Jery:Doorman = new Doorman();
    
    Jery.walk("forward");
    i keep getting the error "1170: Function does not return a value."

    what am i doing wrong!!?

    can anyone please write this code out so it works and so i can study it?


    cheeers
    FlashX

    ________________________
    The mind lies, it only hears what it wants to hear.

  2. #2
    Senior Member
    Join Date
    Jan 2011
    Posts
    171
    ActionScript Code:
    package {
        public class Doorman {

            public function Doorman() {

            }
            public function walk(characterDirection:String):void {
                if (characterDirection == "forward") {
                    trace(characterDirection);
                }
            }
        }
    }

    ActionScript Code:
    var Jery:Doorman = new Doorman();
    Jery.walk("forward");

    There is no return datatype, so it should be void, If you want to go with your code structure then:

    ActionScript Code:
    package {
        public class Doorman {

            public function Doorman() {

            }
            public function walk(characterDirection:String):String {
                if (characterDirection == "forward") {
                    return characterDirection;
                }
                return "Wrong Input";
            }
        }
    }

    ActionScript Code:
    var Jery:Doorman = new Doorman();
    trace(Jery.walk("forward"));




    arkitx
    Last edited by arkitx; 07-14-2011 at 12:22 PM.

  3. #3
    Senior Member
    Join Date
    May 2002
    Posts
    359
    Awesome! Thank you so much for your help! I havnt tested it yet but once I get on my pooter I'll let you know how it goes. I'm just struggling gettin my head round it.

    Cheers
    FlashX

    ________________________
    The mind lies, it only hears what it wants to hear.

  4. #4
    Senior Member
    Join Date
    May 2002
    Posts
    359
    just checked it, works fantastic! thank you again
    FlashX

    ________________________
    The mind lies, it only hears what it wants to hear.

  5. #5
    Senior Member
    Join Date
    Jan 2011
    Posts
    171
    What are you studding/practicing right now?

    About Classes.....?



    arkitx

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