PDA

View Full Version : OOPs Question flash 8 as2.0?


sskully
11-07-2007, 04:38 PM
Hi, I'm wondering what's the best way to go about setting up this class.
I basically want a user to be able to create an object and assign a image to.
Then the user can create as many textfields as they want for that object.

I'm not sure how to associate the new textField to the object.
I can have a property for the image, but if the user can make as many textfields as they want, how would I set a property of the textFields for the object?
Should I have an array that holds the textFields properties?

Here's an example I'm working with:
http://www.visualstrategies.ca/forma...omponent05.swf

Thanks for the help!

Flash Gordon
11-07-2007, 08:16 PM
I'm not sure how to associate the new textField to the object.
You could always do something like this:

var dict:Object = new Object();
dict[txt] = assObj;

trace( dict[txt] ); // assObj

sskully
11-07-2007, 08:54 PM
Thanks for your help!
I basically took your code and created a class out of it.

Here's the class:

class CreateField extends MovieClip {
private var identifier:String;
private var textFields:Object = new Object();
private var tfArray:Array = new Array();

public function CreateField(){
}

public function makeField(fld_name:String, fld_content:String, fld_depth:Number, x_loc:Number, y_Loc:Number ){

identifier = fld_name;

textFields[identifier] = _root.createTextField(identifier, fld_depth, x_loc, y_Loc, 100, 100);
textFields[identifier].text = fld_content;

tfArray.push(textFields[identifier]);

for (var prop in tfArray) {
trace("myObject."+prop+" = "+tfArray[prop]);
}

}

}

Is this right? Is there a better way to do this?

Thanks again.

Flash Gordon
11-08-2007, 12:48 AM
It's right if it works. The code I posted in an AS 2.0 verion of the AS 3.0 Dictionary class. I don't really know your needs so I'm afraid I can't help too much more.

sskully
11-14-2007, 03:42 PM
Thanks for you help, sorry i didn't reply sooner I've been sick.

Thanks again