PDA

View Full Version : [AS2] textarea issue..


elinaf
07-03-2009, 09:38 AM
Hello,
I' m a newbie in actionscript and i have an issue with textarea. I have a canvas and i want to place textareas on it randomly. The textareas are placed on the stage through a button. When i release the button for the first time everything works just fine! The size is ok, the textarea is editable as i want it, etc.

My problem starts when i'm trying to create more textareas. On the second textarea, the first one disappears(and i want them all on the canvas)and there are two textareas that appear on the canvas, a very small one and one in the desirable size, but none of them are editable!!!

On the third release of the button(third textarea) i have the small and the large textareas as in the last step, BUT now the large textarea is editable again...

I have been working on this thing for a long long time and i have absolutely no idea of what i am doing wrong. If someone could help me out with this i would really really really appreciate it!!

This is my code:

plusText.onRelease = function() {
addText();
};

function addText() {
canvasClip.createEmptyMovieClip("texta",canvasClip.getNextHighestDepth());
canvasClip.texta.createClassObject(mx.controls.Tex tArea, "textArea", canvasClip.getNextHighestDepth() , {editable:true, html:true, wordWrap:true});
canvasClip.texta.textArea.setSize(150,225);
canvasClip.texta.textArea.move(109,50);
canvasClip.texta.textArea._x = random(200);
canvasClip.texta.textArea._y = random(200);
myArray[currentPage].addTreeNode("text_" + textID, canvasClip.textArea);
pages[currentPage].push(canvasClip.texta.textArea);
textID++;
}



Thx a lot!

uncleunvoid
07-03-2009, 10:18 AM
why arent you just using a textfield?

you also seem to be using the same object to reference the text

canvasClip.texta

maybe the overwriting of the old one is killing previous ones. donno I never use textareas.

I would normally approach this rather like:


textlist = new Array

function createNewText(){
textField = new Textfield(Math.random()*Stage.width,etc, width, height, textlist.length)
textField.border = true
textField.type = "input"
textField.autoSize = false
textlist.push(textfield)
}

Mouse.addListener(this)
function onMouseDown(){
createNewText()
}

keep in mind this is very rough, but should give you a better idea about the structure. check out the textfield in help, it will help.

elinaf
07-03-2009, 10:40 AM
Thx a lot uncleudvoid!
After all that time that i'm working on it, i cant even remember why i chose textarea over textfield!
I''ll give it a try..

Thx again!

elinaf
07-04-2009, 08:46 PM
So, i tried the textField and it works!! Now i have a minor issue that comes up probably because i have some syntax error..
I want to be able to drag my textfields. I know that a textfield cant be dragged so i tried the two ways that i found.
The first was with a mouse event but it wasn't good because i could stop the dragging:o and generally the movement wasn't very natural.
The second that i liked more, was creating a parent movieclip and drag it, instead of the textfield. My problem is that the second textfield is attached on the same mc and when i start the dragging they are dragged all together...
Probably i have to create each time a different empty movieclip, but i cant get the syntax right..

This is my code:

canvasClip.createEmptyMovieClip("txtb",canvasClip.getNextHighestDepth());
var DragText = canvasClip.txtb.createTextField("textb",canvasClip.getNextHighestDepth(),working_space.ch ildNodes[currentPage].firstChild.childNodes[pst].attributes.posx,working_space.childNodes[currentPage].firstChild.childNodes[pst].attributes.posy,150,225);

canvasClip.txtb.onPress = function(){
canvasClip.txtb.startDrag(true,-204,234,336,-49);

};

canvasClip.txtb.onRelease = canvasClip.txtb.onReleaseOutside = function(){
canvasClip.txtb.stopDrag();
};

i thought doing something like:
canvasClip.createEmptyMovieClip("txtb"+textID,canvasClip.getNextHighestDepth());
but i get an error when i try to call it afterwords.

I would really appreciate any help!!!!!!!!
Thx a lot.

elinaf
07-07-2009, 07:39 AM
I figured it out after all! I used the eval() function and it worked... :-)