Need help for one little AS3 code

Hello I am new in Action Script 3 and I am starting with little flash based page. But got problem on second script please help me. Here are my files:

sims3Text.as

package{
    public class Sims3Text{ 
        public static function sims3(fWord:String):String{ 
            var sims3:String = fWord;
            return sims3;
        }
    }
}

in *.fla

var mysims3Text:Sims3Text = new Sims3Text();
sims3Text.text = Sims3Text.sims3("teeest");

but the code isnt exporting I look everything should work but nooo. Please help me

Thanks in advice.

Okay there’s a few fundamental flaws going on here : )

lets start from the top;

package defines the location of your class.

ie package com.gfx { says that the class is located in /com/gfx/

Class statement defines the filename of your class.

ie public class Sims3Text says that your filename is Sims3Text.as

Your class doesn’t have a constructor, so there’s no way you can do a “new” thing with it.

A constructor is a public function that has the same name as your class and returns void.

public function Sims3Text():void {
//hello
};

is a constructor for that class.

You are also using a public STATIC function, which basically means that it will be available before instantiation (no new() needed)

soooooooo… even though I don’t understand WHY you would want to do this, maybe just for practice… if it’s just for practice, it should be something like this;

class;


package {

	public class Sims3Text { 
	
		public function Sims3Text():void {
		};
		
		public static function sims3(fWord:String):String{ 
			return fWord;
		};
	};
};

.fla


import Sims3Text;
trace(Sims3Text.sims3("hellooooo"));

first thanks
second YES for practice
third thanks but gives me error on this line: trace(Sims3Text.sims3(“hellooooo”));
error: 1061: Call to a possibly undefined method sims3 through a reference with static type flash.text:TextField.

hope you help me :S
thanks in advance

Do you have a textfield on stage with an instance name Sims3Text?

yes i do

Then either remove it, change its instance name, or change the class name (Best choice would probably be changing its instance name).

The reason you get the error (someone correct me if I’m wrong), is because flash is looking for the method sims3 within the textfield, which has the instance name Sims3Text. There is no method sims3 within the textfield class, so flash throws an error.

Basically don’t have your objects or variables with the same name as your classes, a simple way to avoid this problem is to name your objects and variables starting with lowercase letters, and your classes starting with uppercase.

Hope that helps.