# Need help for one little AS3 code

**URL:** <https://forum.kirupa.com/t/need-help-for-one-little-as3-code/265192>\
**Category:** flash\
**Created:** [July 5, 2008, 5:57pm UTC](https://forum.kirupa.com/t/need-help-for-one-little-as3-code/265192 "2008-07-05T17:57:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![westony](https://avatars.discourse-cdn.com/v4/letter/w/ebca7d/32.png) [@westony](https://forum.kirupa.com/u/westony)\
**Post date:** [July 5, 2008, 5:57pm UTC](https://forum.kirupa.com/t/need-help-for-one-little-as3-code/265192/1 "2008-07-05T17:57:39Z")

</div>

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

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

```

in \*.fla

```auto
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.

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [July 5, 2008, 6:14pm UTC](https://forum.kirupa.com/t/need-help-for-one-little-as3-code/265192/2 "2008-07-05T18:14:33Z")

</div>

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;

```auto

package {

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

```

.fla

```auto

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

```

---

<div class="post-metadata">

**Author:** ![westony](https://avatars.discourse-cdn.com/v4/letter/w/ebca7d/32.png) [@westony](https://forum.kirupa.com/u/westony)\
**Post date:** [July 5, 2008, 6:27pm UTC](https://forum.kirupa.com/t/need-help-for-one-little-as3-code/265192/3 "2008-07-05T18:27:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tpspoons](https://avatars.discourse-cdn.com/v4/letter/t/b4bc9f/32.png) [@tpspoons](https://forum.kirupa.com/u/tpspoons)\
**Post date:** [July 6, 2008, 3:08pm UTC](https://forum.kirupa.com/t/need-help-for-one-little-as3-code/265192/4 "2008-07-06T15:08:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![westony](https://avatars.discourse-cdn.com/v4/letter/w/ebca7d/32.png) [@westony](https://forum.kirupa.com/u/westony)\
**Post date:** [July 6, 2008, 4:37pm UTC](https://forum.kirupa.com/t/need-help-for-one-little-as3-code/265192/5 "2008-07-06T16:37:33Z")

</div>

yes i do

---

<div class="post-metadata">

**Author:** ![tpspoons](https://avatars.discourse-cdn.com/v4/letter/t/b4bc9f/32.png) [@tpspoons](https://forum.kirupa.com/u/tpspoons)\
**Post date:** [July 6, 2008, 4:43pm UTC](https://forum.kirupa.com/t/need-help-for-one-little-as3-code/265192/6 "2008-07-06T16:43:33Z")

</div>

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.
