Flash CS4, Inactive buttons - actionscript-3

I have no syntax errors when I run this code. I checked the variables and the functions in the action panel and it works fine. But, when I remove the codes from the action panel, and try to run the .as file nothing happens when I click the button.
Here's my code:
package
{
import flash.display.*;
import flash.events.MouseEvent;
import flash.text.*;
import flash.display.MovieClip;
public class U1A4_Sommeil extends MovieClip
{
private var monMessage:TextField = new TextField;
private var maMiseEnForme: TextFormat = new TextFormat;
public function U1A4_Sommeil ()
{
btnSoumettre.addEventListener(MouseEvent.CLICK,Calcule);
}
private function Calcule (event:MouseEvent):void
{
maMiseEnForme.font= "Arial";
maMiseEnForme.size = 20;
maMiseEnForme.color = 0xFF0000;
maMiseEnForme.bold = true;
monMessage.autoSize = TextFieldAutoSize.LEFT;
monMessage.defaultTextFormat = maMiseEnForme;
monMessage.x = 260;
monMessage.y = 260;
monMessage.border = true;
var intAn : int = int(txtAn.text) - int(txtAnNaissance.text);
var intMois : int = int(txtMois.text) - int(txtMoisNaissance.text);
var intJour : int = int(txtJour.text) - int(txtJourNaissance.text);
var strResultat : String = ("Tu es agé de "+ (intAn*365+intMois*30+intJour) + " jours."
+ "\n"
+ "Tu as dormi " + ((intAn*365 + intMois*30 + intJour)*8) + " heures"
+ "\n"
+ "depuis ta naissance.");
monMessage.text = strResultat;
addChild (monMessage);
}
}
}

I think that your have just to add your U1A4_Sommeil class as your document class using your document properties :
Or, from File Menu > ActionScript Settings... then :
Hope that can help.

Related

Access of undefined propety and other errors (AS3)

ok so I am trying to work on making my scripts external .as files.
I had them on the timeline and they worked fine but when I put them in the as file they don't work at all.
This is my code as of right now
so I got the script working externally thank you very much :)
I just need to addchild to the stage. I use
import Scripts.resources.main;
var Main:main = new main;
addChild(Main);
In my external script I addchild in the main function now.
package Scripts.resources
{
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLLoader;
import flash.net.URLRequestMethod;
import flash.events.OutputProgressEvent;
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.EventDispatcher;
public class main extends EventDispatcher{
private var _stage:Stage;
var url:String = "php/data_user.php";
//declare our graphic vars
var stmBar:resourceBar;
var tenBar:resourceBar;
var potBar:resourceBar;
var spdBar:resourceBar;
var crtBar:resourceBar;
var awrBar:resourceBar;
var resBar:resourceBar;
var statUp:Sprite;
//This Returns the number of milliseconds since midnight January 1, 1970
//Tacking the time variable at the end of your php file locations will ensure their is no caching
var now:Date = new Date();
var time:Number = now.getTime();
/*
* These should point to your PHP files. I recommend NOT using an http path because accessing
* the site via 'www.yoursite.com' versus 'yoursite.com' makes a difference and will cause undefined
* issues. Instead use a relative path like: var registerLocation:String = "membership/php/register.php";
*/
var registerLocation:String = "php/register.php" + "?" + time;
var loginLocation:String = "php/login.php" + "?" + time;
var editProfileLocation:String = "php/editprofile.php" + "?" + time;
var forgotPWLocation:String = "php/forgotpw.php" + "?" + time;
var statsLocation:String = "php/user_stats.php" + "?" + time;
var statsGylph:String = "php/data_user.php" + "?" + time;
//userInfo is the Object that gets populated that stores all of the users information.
var userInfo:Object = new Object();
//The minimum length of a password.
var passwordLength:Number = 4;
/*
* var cookie refers to swfObjects addVariable. If you look at membership.php, where swf
* object is defined, addVariable shows a var called usercookie.
* This help decide if the program should remember the users username or not.
*/
//cookieUserName would be the username that gets put into the user field if the cookie has been set
public function main(stage:Stage)
{
_stage = stage;
var _loader:URLLoader = new URLLoader();
var _request:URLRequest = new URLRequest(url + "?id=" + userInfo.id);
_request.method = URLRequestMethod.GET;
_loader.addEventListener(Event.COMPLETE, onLoadData);
_loader.load(_request);
_stage.addChild(stmBar);
stmBar.x = -50;
stmBar.y = 200;
}
public function MyClass(){
this.addEventListener(Event.ADDED_TO_STAGE, addedToStage);
}
private function addedToStage(e:Event):void {
this.removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
//this code will run after you've added this object to the stage
//it is the equivalent of when timeline code runs
}
function onLoadData(e:Event):void {
var str:String = e.target.data;
var array:Array =str.split("-");
for(var i:int;i < array.length; i++)
output(i+1,array[i]);
}
public function output(field:Number,i:int):void
{
if (field == 5)
{
stmBar = new resourceBar(0, 0, i, "Stamina", 0x990000);
stmBar.x = -200;
stmBar.y = 50;
}
else if (field == 6)
{
tenBar = new resourceBar(0, 0, i, "Tenacity", 0xFF9900);
tenBar.x = 200;
tenBar.y = 50;
}
else if (field == 7)
{
potBar = new resourceBar(0, 0, i, "Potency", 0xCC3399);
potBar.x = -200;
potBar.y = 100;
}
else if (field == 8)
{
spdBar = new resourceBar(0, 0, i, "Speed", 0x00CC00);
spdBar.x = 200;
spdBar.y = 100;
}
else if (field == 9)
{
crtBar = new resourceBar(0, 0, i, "Crit", 0x009999);
crtBar.x = -200;
crtBar.y = 150;
}
else if (field == 10)
{
awrBar = new resourceBar(0, 0, i, "Awareness", 0x3399CC);
awrBar.x = 200;
awrBar.y = 150;
}
else if (field == 11)
{
resBar = new resourceBar(0, 0, i, "Resistance", 0x999999);
resBar.x = -200;
resBar.y = 200;
addEventListener(Event.ENTER_FRAME, onLoop);
}
function onLoop(e:Event):void
{
stmBar.change(1);
tenBar.change(1);
potBar.change(1);
spdBar.change(1);
crtBar.change(1);
awrBar.change(1);
resBar.change(1);
}
}
}
}
my problem is it won't add the children in the main function when I addchild of main. am I able to add a child with children inside it?
In class files, all code needs to be wrapped in a function. So where you have:
_loader = new URLLoader();
_request = new URLRequest(url + "?id=" + (STAGE.parent as MovieClip).userInfo.id);
_request.method = URLRequestMethod.GET;
_loader.addEventListener(Event.COMPLETE, onLoadData);
_loader.load(_request);
You need to place it in a function for the code to be valid. If you want that bit of code to run right away, then you can place it in a constructor (that is the function in class that runs when you instantiate with the new keyword, eg new main(). If main is your document class, then the constructor is the very first code to run in the application.
Constructors are public functions that have the exact name of your Class.
public function main(){
_loader = new URLLoader();
_request = new URLRequest(url + "?id=" + (STAGE.parent as MovieClip).userInfo.id);
_request.method = URLRequestMethod.GET;
_loader.addEventListener(Event.COMPLETE, onLoadData);
_loader.load(_request);
}
Something to keep in mind, is that in the constructor of display objects, the stage/parent/root keywords will NOT have any value, as those are populated once the display object has been added to the display. So, it's common to use this approach:
package MyClass extends Sprite {
public function MyClass(){
this.addEventListener(Event.ADDED_TO_STAGE, addedToStage);
}
private function addedToStage(e:Event):void {
this.removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
//this code will run after you've added this object to the stage
//it is the equivalent of when timeline code runs
}
}
Also, a tip now that you are writing class files - follow the convention of making class names start with an Uppercase letter, and instances of classes start with lowercase letters.

Passing variables from actionscript 3 to actionscript 2

I have a swf written in AS3 which loads an AS2 swf.
AS3 code:
var url:String = "as2.swf?myvar=hello";
var spURL:Array = url.split("?");
var urlVars:URLVariables = new URLVariables();
urlVars.decode(spURL[1]);
var req:URLRequest = new URLRequest( spURL[0] );
req.data = urlVars;
req.method = URLRequestMethod.GET;
AS2 code:
trace(_root.myvar);
but nothing traced!
I found solution to my question.
Full source code bellow
AS3: with a movieclip named "as2btn" and a text field named "as3_log". The publish class name is "main_as3"
package {
import flash.display.*;
import flash.events.*;
import flash.net.*;
public class main_as3 extends MovieClip {
public var ld:Loader;
public function main_as3() {
// constructor code
this.as2btn.addEventListener(MouseEvent.MOUSE_DOWN, as2Load);
this.logMessage("Initialized!");
}
public function logMessage(msg:String)
{
this.as3_log.appendText("AS3: " + msg + "\n");
}
public function as2Load(evt:MouseEvent)
{
if (this.ld) {
this.ld.unloadAndStop();
this.ld = null;
}
var url:String = "as2.swf?myvar=1rewr&myvar2=1234";
var spURL:Array = url.split("?");
var urlVars:URLVariables = new URLVariables();
urlVars.decode(spURL[1]);
var req:URLRequest = new URLRequest(spURL[0]);
req.data = urlVars;
req.method = URLRequestMethod.GET;
this.ld = new Loader();
this.ld.load(req);
addChild(this.ld);
}
}
}
AS2: with a movieclip linkage identifier "main" and class name "main_as2" includes a text field named "as2_log"
class main_as2 extends MovieClip
{
var _parent;
function main_as2()
{
super();
this.gotoAndStop(1);
this.logMessage("Initialized!");
this.logMessage("_parent.myvar: " + _parent.myvar);
}
function logMessage(msg:String)
{
this["as2_log"].text = this["as2_log"].text + "AS2: " + msg + "\n";
}
}

How do i pass String from Php to VO file to another .as file in AS3?

Hi I am pretty new to AS3, i am trying to parse some data from php to a VO file, and then transfer the string of data into another .as file where it will put the data into boxes. I am stuck in how do i parse the data from the VO file into the other .as File(Pulling the data from php into BookVO, then parsing BookVO to VectorTest). I tried tracing the data in BookVO, it works ok, but i can't get the data from BookVO to VectorTest.
Please help, thanks
BookVO.as
package com.clark
{
import flash.display.*;
import flash.net.*;
import flash.events.*;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLLoaderDataFormat;
import flash.net.URLVariables;
public class BookVO
{
public var nobed1:String;
public var LoZip1:String;
public var rangelow1:String;
public var rangehigh1:String;
public var Bend:URLRequest;
public var variabless:URLVariables;
public var nLoader:URLLoader;
public function BookVO() {
Bend = new URLRequest("http://localhost/Autoresult.php");
Bend.method = URLRequestMethod.POST;
variabless = new URLVariables();
Bend.data = variabless;
nLoader = new URLLoader();
nLoader.dataFormat = URLLoaderDataFormat.TEXT;
nLoader.addEventListener(Event.COMPLETE,Jandler);
nLoader.load(Bend);
// handler for the PHP script completion and return of status
function Jandler(event:Event) {
var responseVariables: URLVariables = new URLVariables(event.target.data);
this.nobed1 = responseVariables.nobed1 ;
this.LoZip1 = responseVariables.LoZip1;
this.rangelow1 = responseVariables.rangelow1;
this.rangehigh1 = responseVariables.rangehigh1;
}
}
}
}
VectorTest.as
package com.clark
{
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.display.Sprite;
public class VectorTest extends MovieClip
{
public function VectorTest()
{
super();
var books:Vector.<BookVO> = new Vector.<BookVO>();
for (var i:int = 0; i < length; i++)
{
var book:BookVO = new BookVO();
book.nobed1 = "nobed1";
book.LoZip1 ="LoZip1";
book.rangelow1 = "rangelow1";
book.rangehigh1 ="rangehigh1";
books.push(book);
}
for (var j:int = 0; j < books.length; j++)
{
trace("Test", j, "has a name of", books[j].nobed1);
trace("Test", j, "Zip", books[j].LoZip1);
trace("Test", j, "ranglow", books[j].rangelow1);
trace("Test", j, "rangehigh", books[j].rangehigh1);
books[j].nobed1;
books[j].LoZip1;
books[j].rangelow1;
books[j].rangehigh1;
}
var currentY:int = 270;
for (var k:int = 0; k < books.length; k++)
{
var Bolder:Listing2 = new Listing2();
Bolder.x=80;
var tf:TextField = new TextField();
var tf1:TextField = new TextField();
tf1.width = 100;
var tf2:TextField = new TextField();
tf2.width = 100;
tf.defaultTextFormat = new TextFormat("Arial", 12, 0, null, null, null, null, null, TextFormatAlign.CENTER);
tf.width = 100;
tf.autoSize = TextFieldAutoSize.CENTER;
tf1.width = 100;
tf1.autoSize = TextFieldAutoSize.CENTER;
tf2.autoSize = TextFieldAutoSize.CENTER;
tf2.width = 100;
tf1.y= tf.height+5;
// Pulling the textfields content out from the current bookVO
tf2.text = books[k].nobed1;
tf1.text = books[k].rangelow1;
tf.text = books[k].rangehigh1;
tf1.x = (Bolder.height-tf.height)*.5
tf2.x = (Bolder.height-tf.height)*.5
tf.x = (Bolder.height-tf.height)*.5
tf.y = (Bolder.height-tf.height)*.15
Bolder.addChild(tf);
Bolder.addChild(tf1);
Bolder.addChild(tf2);
// position the object based on the accumulating variable.
Bolder.y = currentY;
addChild(Bolder);
currentY += Bolder.height + 35;
}
}
}
}
First off, good job on your classes. Much better than most people who say they're new to AS3. ;)
That said...
In VectorTest, you're calling super() on a MovieClip. You don't need this.
If you're not using the timeline of a MovieClip (which, I'd recommend not using anyway), extend Sprite instead; it's lightweight as it doesn't carry the timeline baggage MovieClip does.
Your first for loop in VectorTest Constructor loops to length... of no array.
You're overwriting the properties of BookVO in that loop, which should be populated by your URLLoader. This is superfluous.
Your second loop references the 4 properties of BookVO, neither reporting or setting the variables (ie., books[j].nobed1;). Might want to remove that.
In BookVO, you've written a nested function. Unless you're dealing with a massive number of variables and have issues with variable scope, don't do it. As it stands, the only variables Jandler() is accessing are already Class level globals.
Loading data is an asynchronous operation, meaning, data doesn't populate instantly (LoadRequest > Wait > ProgressEvent > Wait > LoadComplete). Because you're both instantiating BookVO and reading the properties in the same function, all you'll get are null properties. Unlike the VectorTest constructor, because Jandler() is called on Event.COMPLETE (asynchronously), it will have access to the variables you're looking for.
Try this instead...
You'll still need to address the length of how many books you want to instantiate, however, I've split out your reading of the properties from the constructor, and added a reference to the method to call when the loading is complete.
It will print out all the variables, and if it is the last book in your Vector, it'll call finish() which... um... does the rest of what you were doing. :)
-Cheers
BookVO Updated 2013.11.07 # 12:30 AM
package com.clark{
import flash.display.*;
import flash.net.*;
import flash.events.*;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLLoaderDataFormat;
import flash.net.URLVariables;
public class BookVO {
public var nobed1:String;
public var LoZip1:String;
public var rangelow1:String;
public var rangehigh1:String;
public var Bend:URLRequest;
public var variabless:URLVariables;
public var nLoader:URLLoader;
private var callMethod:Function;
public var data:Object;
public function BookVO(listener:Function = null) {
Bend = new URLRequest("http://localhost/Autoresult.php");
Bend.method = URLRequestMethod.POST;
variabless = new URLVariables();
Bend.data = variabless;
nLoader = new URLLoader();
nLoader.dataFormat = URLLoaderDataFormat.TEXT;
nLoader.addEventListener(Event.COMPLETE,Jandler);
nLoader.load(Bend);
if (listener != null) {
callMethod = listener;
}
}
public function Jandler(event:Event) {
// handler for the PHP script completion and return of status
var responseVariables:URLVariables = new URLVariables(event.target.data);
data = event.target.data;
report(data);
if (callMethod != null) {
callMethod(this);
}
}
private function report(obj:*, prefix:String = ""):void {
for (var k in obj) {
var type:String = getType(obj[k]);
if (type == "Array" || type == "Object" || type == "Vector") {
trace(prefix + k + ": (" + type + ") ¬")
report(obj[k], prefix + " ")
} else {
trace(prefix + k + ":" + obj[k] + " (" + type + ")")
}
}
}
private function getType(value:*):String {
// Returns the class name of object passed to it.
var msg:String = flash.utils.getQualifiedClassName(value);
if (msg.lastIndexOf("::") != -1) {msg = msg.split("::")[1];}
return msg;
}
}
}
VectorTest
package com.clark {
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.display.Sprite;
public class VectorTest extends MovieClip {
public var books:Vector.<BookVO>;
public function VectorTest() {
books = new Vector.<BookVO>();
for (var i:int = 0; i < length; i++) {
var book:BookVO = new BookVO(response);
books.push(book);
}
}
private function response(book:BookVO):void {
trace("Name: ", book.nobed1);
trace("Zip: ", book.LoZip1);
trace("ranglow: ", book.rangelow1);
trace("rangehigh: ", book.rangehigh1);
// call finish() if this is the last book.
if (books.indexOf(book) == books.length - 1) {
finish();
}
}
private function finish():void {
var currentY:int = 270;
for (var k:int = 0; k < books.length; k++) {
var Bolder:Listing2 = new Listing2();
Bolder.x=80;
var tf:TextField = new TextField();
var tf1:TextField = new TextField();
tf1.width = 100;
var tf2:TextField = new TextField();
tf2.width = 100;
tf.defaultTextFormat = new TextFormat("Arial", 12, 0, null, null, null, null, null, TextFormatAlign.CENTER);
tf.width = 100;
tf.autoSize = TextFieldAutoSize.CENTER;
tf1.width = 100;
tf1.autoSize = TextFieldAutoSize.CENTER;
tf2.autoSize = TextFieldAutoSize.CENTER;
tf2.width = 100;
tf1.y = tf.height+5;
// Pulling the textfields content out from the current bookVO
tf2.text = books[k].nobed1;
tf1.text = books[k].rangelow1;
tf.text = books[k].rangehigh1;
tf1.x = (Bolder.height-tf.height)*.5
tf2.x = (Bolder.height-tf.height)*.5
tf.x = (Bolder.height-tf.height)*.5
tf.y = (Bolder.height-tf.height)*.15
Bolder.addChild(tf);
Bolder.addChild(tf1);
Bolder.addChild(tf2);
// position the object based on the accumulating variable.
Bolder.y = currentY;
addChild(Bolder);
currentY += Bolder.height + 35;
}
}
}
}

Use MouseEvent for getting Object`s public variables

I have a simple problem which is not easy at the moment. this is a text field class which add a text field to a movieclip (passed from root class) and also save(buffer) some data (like xml file name) in it`s public variables:
package src {
import flash.display.Shape;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
public class menuitem00 extends Shape {
public var activateFlag:Boolean = false;
public var name00:String = "";
public var xml00:String = "";
public var txt00:TextField = new TextField();
private var OM:MovieClip;
private var id00:Number = 0;
public function menuitem00(n:int ,OE:MovieClip ,xmlf:String):void {
trace (" Text Field Object with buffer ");
OM = OE; id00 = n; xml00 = xmlf;
}
public function init():void{
// textfield
txt00.selectable = false;
txt00.autoSize = TextFieldAutoSize.LEFT;
txt00.defaultTextFormat = new TextFormat("Impact", 36,0x66AAFF);
txt00.text = name00;
txt00.border = true;
txt00.borderColor = 0x00FF00;
txt00.sharpness = 100;
txt00.x = 0;
txt00.y = (id00 * txt00.height) + 1;
txt00.z = 0;
OM.addChild(txt00);
}
}
}
.. now I use a for loop to add instance of that class to a movie clip on stage:
for (var i:int = 0; i<Bunker[0]["trans0size"]; i++) {
menuData[i] = new menuitem00(i, menu_mc, Bunker[0]["transfile0" + i]);// pass i , a movieclip named menu_mc and an xml file name
menuData[i].name00 = Bunker[0]["transtitle0" + i]; // pass text
menuData[i].activateFlag = true; // set actveFlag to true
menuData[i].init(); // run init() inside the instance. it adds textfield to the menu_mc and also set name00 as Text for the textField
}
also I add mouse event for clicking on the stage,
stage.addEventListener(MouseEvent.CLICK, clk, false, 0, true);
public function clk(evt:MouseEvent):void{ //// mouse
trace (" Name: " + evt.target.text);
//trace (evt.target.xml00);
}
HERE IS MY PROBLEM --> I want to get "xml00" var from that instance on the stage by mouse click but, trace (evt.target.xml00); is not working .. also trace (evt.target.name00); is not working. I can get everything like .alpha or .text from txt00 but not other variables in my object. Any idea ?
don't add the click-listener to the STAGE but to you object.
menuData[i].addEventListener(MouseEvent.CLICK, clk, ...);
and add the following line to your menuitem00 class:
this.mouseChildren = false;
so you can be sure that the evt.target is an object of this class and not a child (like the textfield or something else).
edit
if you want to keep the stage-listener, try this:
stage.addEventListener(MouseEvent.CLICK, clk, ...);
private function clk (evt:MouseEvent):void
{
if (evt.currentTarget is menuitem00)
{
var item:menuitem00 = evt.currentTarget as menuitem00;
trace(item.xml00); // or any other public variable
}
}
but still add the mouseChildren = false; to your class.
edit2
make the menuitem00 class a sprite (and rename it pls):
public class MenuItem extends Sprite {
private var _activateFlag:Boolean;
private var _xml:String;
private var _txt:TextField;
private var _id:Number;
public function MenuItem (n:int, xmlf:String) {
trace (" Text Field Object with buffer ");
_id = n;
_xml = xmlf;
_activeFlag = true;
this.mouseChildren = false;
// create txt
_txt = new TextField();
// do the formating here ...
this.addChild(_txt);
}
public function getXml():String {
return _xml;
}
}
in the for loop you would do sth like this:
for (var i:int = 0; i<Bunker[0]["trans0size"]; i++) {
var item:MenuItem = new MenuItem(i, Bunker[0]["transfile0" + i]);
item.addEventListener(MouseEvent.CLICK, clk, false, 0, true);
menu_mc.addChild(item);
menuData[i] = item;
}
private function clk (evt:MouseEvent):void {
var item:MenuItem = evt.target as MenuItem;
if (item != null) {
trace(item.getXml()); // use a getter and don't access the variable directly
}
}
and pls re-read your actionscript (or programming) books, you're doing some really bad things i your code that you shouldn't.

TypeError: Error #2007: Parameter child must be non-null

I am running the following piece of code:
package {
import fl.controls.Button;
import fl.controls.Label;
import fl.controls.RadioButton;
import fl.controls.RadioButtonGroup;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextFieldAutoSize;
public class RadioButtonExample extends Sprite {
private var j:uint;
private var padding:uint = 10;
private var currHeight:uint = 0;
private var verticalSpacing:uint = 30;
private var rbg:RadioButtonGroup;
private var questionLabel:Label;
private var answerLabel:Label;
private var question:String = "What day is known internationally as Speak Like A Pirate Day?";
private var answers:Array = [ "August 12", "March 4", "September 19", "June 22" ];
public function RadioButtonExample() {
setupQuiz();
}
private function setupQuiz():void {
setupQuestionLabel();
setupRadioButtons();
setupButton();
setupAnswerLabel();
}
private function setupQuestionLabel():void {
questionLabel = new Label();
questionLabel.text = question;
questionLabel.autoSize = TextFieldAutoSize.LEFT;
questionLabel.move(padding, padding + currHeight);
currHeight += verticalSpacing;
addChild(questionLabel);
}
private function setupAnswerLabel():void {
answerLabel = new Label();
answerLabel.text = "";
answerLabel.autoSize = TextFieldAutoSize.LEFT;
answerLabel.move(padding + 120, padding + currHeight);
addChild(answerLabel);
}
private function setupRadioButtons():void {
rbg = new RadioButtonGroup("question1");
createRadioButton(answers[0], rbg);
createRadioButton(answers[1], rbg);
createRadioButton(answers[2], rbg);
createRadioButton(answers[3], rbg);
}
private function setupButton():void {
var b:Button = new Button();
b.move(padding, padding + currHeight);
b.label = "Check Answer";
b.addEventListener(MouseEvent.CLICK, checkAnswer);
addChild(b);
}
private function createRadioButton(rbLabel:String, rbg:RadioButtonGroup):void {
var rb:RadioButton = new RadioButton();
rb.group = rbg;
rb.label = rbLabel;
rb.move(padding, padding + currHeight);
addChild(rb);
currHeight += verticalSpacing;
}
private function checkAnswer(e:MouseEvent):void {
if (rbg.selection == null) {
return;
}
var resultStr:String = (rbg.selection.label == answers[2]) ? "Correct" : "Incorrect";
answerLabel.text = resultStr;
}
}
}
This is from Adobe Livedocs. http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/
I have added a Radiobutton to stage and then deleted it so that its there in the library.
However I am getting the following error
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChildAt()
at fl.controls::BaseButton/fl.controls:BaseButton::drawBackground()
at fl.controls::LabelButton/fl.controls:LabelButton::draw()
at fl.controls::Button/fl.controls:Button::draw()
at fl.core::UIComponent/::callLaterDispatcher()
Can anyone tell me what is going on and how to remove this error.
the problem here is that you have not included a Button Component to your library.
drag a Button from the components panel (in addition to the RadioButton component) into your library (or drag it to the stage and delete it). the runtime error will go away and you'll have a working "Check Answer" button below the questionare.