A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Classes, Packages And A Blank Stage!

  1. #1
    Senior Member Ex-Ess's Avatar
    Join Date
    Nov 2002
    Location
    York (England)
    Posts
    588

    Classes, Packages And A Blank Stage!

    Hello!
    I'm new to as3 and although I'm getting my head around it I'm struggling with one problem. I've been working through lots of tutorials and am able to build classes that don't error but also don't put anything on the stage.

    I have Starter_1.as file stored in a folder called com...this is the script for that file:

    Code:
    package com {
    	import flash.display.Sprite;
    	import flash.text.TextField;
    	
    	public class Starter_1 extends Sprite {
    		private var tField:TextField;
    		
    		public function Starter_1 () {
    	      	myTest();
    	    }
    		
    		private function myTest():void {
    			tField = new TextField();
    			tField.autoSize = "left";
    	        tField.background = true;
    	        tField.border = true;
    	        tField.x = 20;
    	        tField.y = 75;
    	        tField.text = "Hello You, what is your name?";
    			addChild(tField);
    		}
    	}
    }
    this is a simple tutorial I worked through.

    From what I can see the problem is because the addChild(tField) is not referencing the stage in anyway because the script is in an external .as file and not on the timeline (good coding practice I read somewhere?)

    I use this on the timeline to try put the text field on the stage:

    Code:
    import com.Starter_1;
    var f1:Starter_1 = new Starter_1();
    How do I get this working?

    Thanks for your help

  2. #2
    flash absorption vessel
    Join Date
    Jul 2009
    Posts
    31
    To have it reference the stage you need to add it to the stage! addChild(f1). Because your class extends a DisplayObject (Sprite), you need to add it to the display list to see anything in it.

  3. #3
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Put Starter_1 in the Class field where the Properties are to make it a Document class or add this line
    addChild(f1);
    to your fla script. Starter_1 needs to be added to the Display list.
    - The right of the People to create Flash movies shall not be infringed. -

  4. #4
    Senior Member Ex-Ess's Avatar
    Join Date
    Nov 2002
    Location
    York (England)
    Posts
    588
    Doh!

    Thank you very much. I was getting confused thinking the addChild in the class was the problem as it can't see the stage.....obviously it doesn't need to. It's taking some getting used to use this way of coding.....does seem sooo much better though!

  5. #5
    flash absorption vessel
    Join Date
    Jul 2009
    Posts
    31
    I win!

    good luck in as3. Post if you need more help.

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