Reputation: 38190
I'm following tutorial here
http://www.graphicsxone.com/checkbox-and-as3-in-flash-cs4.html
This is my code in main.as
package {
import flash.display.Sprite;
// import the CheckBox class
import fl.controls.CheckBox;
mport flash.events.*;
public class main extends Sprite {
addEventListener( Event.ADDED_TO_STAGE, init );
// create the CheckBoxes
var NS = new CheckBox();
var SS = new CheckBox();
var ES = new CheckBox();
var WS = new CheckBox();
}
private function init( e:Event ):void
{
removeEventListener( Event.ADDED_TO_STAGE, init );
response_txt.text = 'foo bar baz etc';
}
}
When I test it says
Access of undefined properties response_txt.
New picture http://img217.imageshack.us/i/responsetxt2.jpg/
Upvotes: 0
Views: 2734
Reputation: 179086
It's a simple issue, response_txt
exists on the stage, but the stage hasn't been instantiated when the code is called.
The simple solution is to add an event handler in the class constructor:
import flash.events.Event;
public class main extends Sprite
{
public function main():void
{
addEventListener( Event.ADDED_TO_STAGE, init );
}
private function init( e:Event ):void
{
removeEventListener( Event.ADDED_TO_STAGE, init );
response_txt.text = 'foo bar baz etc';
}
}
Upvotes: 1
Reputation: 11
You don't have an instance of response_txt.
From tutorial:
Take the Text Tool and draw a rectangle to cover the inside of the container.
Set the Text property in the Properties to “Dynamic text” with a instance name of response_txt.
Did you do that?
Upvotes: 1
Reputation: 4234
You never instantiated response_txt.
var response_txt:TextField = new TextField();
response_txt.text = "blah blah blah";
That or you aren't assigning the instance name properly in the flash IDE. I didn't look at the tutorial much but - if your symbol is on the stage, just click on it and be sure to give it the right instance name...
Upvotes: 1