Log in

View Full Version : changing an objects properties or values



evan
07-14-2009, 04:23 PM
This is the doc class that imports an instanceof a textbox from textboxes.as


package
{
//imports
import AS.textboxes

import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ErrorEvent;
import flash.events.ProgressEvent;
import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.xml.XMLDocument;
import flash.events.TimerEvent;
import flash.utils.Timer;

public class shooter extends Sprite
{

//public var playername:String="Evan"
//create an instance of the object from the textboxes class
public var playertext:textboxes;
public function shooter()
{
playertext = new textboxes(playername:String="newname")

addChild(playertext);

//playertext.text=playername;
//AS.textboxes.mytext.text=playername;
}//end constructor

}//end class
}//end package

here is textboxes.as:






package AS
{
import flash.display.*
import flash.events.*
import flash.text.*


public class textboxes extends Sprite
{
//variables
//public var myText=new TextField();
public var mytext:TextField = new TextField();
//public var playername:String="default";
public function textboxes(playername:String)
{
addChild(mytext);
mytext.x=100;
mytext.y=100;
mytext.text=playername;

}//end constructor

//place any private funtions here


}//end class
}//end package

When I create an instance of textboxes in the doc class, I am unable to change the "default" by changing the variable.


Do I have to create a superclass to extend the textboxes class in oder to make it changable?

I have been reading allot now I am trying too see how all this theory is applied and trying to determine what is efficient from what is overkill.

Thanks in advance for looking at this.

punstc
07-15-2009, 12:52 AM
from what you have posted you have a small problem with the way your are making an instance of your class.



playertext = new textboxes(playername:String="newname")


you can go about doing it two ways you have a variable already defined called playername which equals even so you can say



playertext = new textboxes(playername)


or you can define the name right inside



playertext = new textboxes("even")


the class textboxes already knows what its suppose to be recieving so you don't need to give it the variable inside the class and the type it's suppose to be.

Hope that helps