I know people have had similar problems, and I’ve looked at dozens of these instances on the web, reading the code and reading the solutions, but I just can’t wrap my brain around it.
Here is the full error I am getting.
TypeError: Error #2007: Parameter text must be non-null.
at flash.text::TextField/set text()
at visuals::Icons/draw()
at visuals::Icons/set myIcon()
at try_it_out_fla::MainTimeline/frame1()
here is the custom class
package visuals{
import flash.display.MovieClip;
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.net.URLRequest;
import flash.events.ProgressEvent;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.MouseEvent;
import flash.events.Event;
public class Icons extends MovieClip{
private var _label:String;
private var _myIcon:String;
private var _fontName:String;
private var _fontSize:int;
private var _fontColor:uint;
private var _embedFonts:Boolean;
private var _width:Number;
private var _height:Number;
public function Icons(
label:String = "Click Here",
myIcon:String = "images/default.png",
fontName:String = "Arial",
fontSize:int = 14,
fontColor:uint = 0x000000,
embedFonts:Boolean = false,
width:Number = 150,
height:Number = 30) {
_myIcon = myIcon;
buttonMode = true;
mouseChildren = false;
}
private function draw():void{
// this is the TextFormat class
var tFormat:TextFormat = new TextFormat();
tFormat.font = _fontName;
tFormat.size = _fontSize;
tFormat.color = _fontColor;
// this is the TextField attributes
var tField:TextField = new TextField;
tField.multiline = true;
tField.wordWrap = true;
tField.selectable = false;
tField.embedFonts = _embedFonts;
tField.defaultTextFormat = tFormat;
tField.autoSize = TextFieldAutoSize.CENTER;
tField.antiAliasType = AntiAliasType.ADVANCED;
tField.text = _label;
tField.x = _width / 2 - tField.width / 2;
tField.y = _height / 2 - tField.height / 2;
addChild(tField);
loadImage();
}
private function loadImage():void {
var imgRequest:URLRequest = new URLRequest(_myIcon);
var imgLoader:Loader = new Loader();
imgLoader.load(imgRequest);
imgLoader.contentLoaderInfo.addEventListener(Event.OPEN, imgLoaderOpen);
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaderComplete);
this.addChild (imgLoader);
//trace ("load image");
}
private function imgLoaderOpen(e:Event):void {
//trace("imgLoader load started");
}
private function imgLoaderComplete(e:Event):void {
//trace("imgLoader load completed");
}
// START SETTER FUNCTIONS *********************************************************************************************
// creating 'setter' functions that allow private variables in classes to be assigned new values at any time from the outside
// uses the 'set' keyword to create a function that from outside the class can be treated like a property
public function set label(value:String) :void{
_label = value;
draw();
}
public function set myIcon(value:String) :void{
_myIcon = value;
draw();
//trace ("did this happen");
}
public function set fontName(value:String) :void{
_fontName = value;
draw();
}
public function set fontColor(value:int) :void{
_fontColor = value;
draw();
}
public function set fontSize(value:int) :void{
_fontSize = value;
draw();
}
public function set embedFonts(value:Boolean) :void{
_embedFonts = value;
draw();
}
public override function set width(value:Number) :void{
_width = value;
draw();
}
public override function set height(value:Number) :void{
_height = value;
draw();
}
// END SETTER FUNCTIONS *********************************************************************************************
}
}
and here is the full code within the FLA. what it is supposed to do (and did do until I tried to add the text and textfield) was pull an image from a folder and display it within a library object.
import visuals.Icons;
var icon_retrofit:Square = new Square();
icon_retrofit.myIcon = "images/b.png";
addChild(icon_retrofit);
Thanks in advance for any help anyone could give me. This is just confusing the hell out of me at this point. And I thought I was doing so well!