Hi,
I am trying to externalize a class and am having problems getting my class to work. On the flash timeline, I have this function call:
CreateText(lessonTitle, "Headline_1", textWidth, textX, textY - 5, 0xFCAF17, 54, 1, true, 0);
Which calls out to an external class:
package {
import flash.display.*;
import flash.text.*;
public class CreateTextBlock extends MovieClip
{
public function CreateTextBlock()
{
// init
}
public function CreateText(textString:String,
textName:String,
textWidth:Number,
textX:Number,
textY:Number,
textColor:int,
textSize:int,
fontStyle:int,
textWordWrap:Boolean,
myLeading:int):void
{
trace(textString);
trace(textName);
trace(textWidth);
trace(textX);
trace(textY);
trace(textColor);
trace(textSize);
trace(fontStyle);
trace(textWordWrap);
trace(myLeading);
}
}
}
My function call does not recognize CreateText(), but recognizes CreateTextBlock, however, if rename my CreateText function to ChangeTextBlock, I continually receive the error message:
1137: Incorrect number of arguments. Expected no more than 1.
Can anyone help me refactor this to a working class?, or point out my flaw?, hopefully it's platently obvious.
Thanks so much,
Chipleh
Well, I found the answer to most of my question; I wasn't instantiating the class correctly. The solution was:
import CreateTextBlock;
var TextCreator:CreateTextBlock = new CreateTextBlock();
| addChild(TextCreator); |
TextCreator.CreateText(lessonTitle, "Headline_1", textWidth, textX, textY - 5, 0xFCAF17, 54, 1, true, 0);
Also, I'm trying to return the value of textName to the stage, so Flash can destroy the text object when the stage is finished with it. Right now, I'm using getChildByName to destroy the text object, i.e.:
var headLineText:DisplayObject = MovieClip(root).getChildByName("Headline_1");
if(headLineText != null)
{
MovieClip(root).removeChild(headLineText);
}
Before, all the code was happening internally, now that I've externalized the class that creates the text object, the stage seemingly doesn't understand the name of the text object, since it is not being removed anymore. Am I not adding the name to the display list properly? Any suggestions?
~Chipleh
Unfortunately I am anything but adept in class matters.
If you used:
addChild(TextCreator);
to add the object, and that is the object you want to remove, then using:
removeChild(TextCreator);
should be all you need to do, and just after that assign it to be null to remove all traces of it and make it available for GC:
TextCreator = null;
North America
Europe, Middle East and Africa
Asia Pacific