Results 1 to 2 of 2

Thread: changing an objects properties or values

  1. #1
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default changing an objects properties or values

    This is the doc class that imports an instanceof a textbox from textboxes.as

    Code:
    	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:

    Code:
    
    
    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.

  2. #2
    Join Date
    Aug 2007
    Location
    Harrisburg, PA
    Posts
    131
    Thanks
    6
    Thanked 9 Times in 9 Posts

    Default

    from what you have posted you have a small problem with the way your are making an instance of your class.

    Code:
    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

    Code:
    playertext = new textboxes(playername)
    or you can define the name right inside

    Code:
    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

  3. The Following User Says Thank You to punstc For This Useful Post:

    evan (07-16-2009)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •