PDA

View Full Version : how to make the textarea retain its properties after transferring


prasanna
02-16-2009, 10:40 AM
hi, i've a problem with transferring text, i'm transferring the text from one text area to another using the change event, my problem is i'm able to edit the text in original text box like changing the color, font, fontsize etc., and it also changes inthe other text area initially, but if i press spacebar in the original text area the text in the other text area loses all its properties like color, font type etc.,, how to make the other text area retain the text's properties forever.. pls help!
i'm also sending my whole action script code along with this.
I'VE ALSO ATTACHED AN SNAP SHOT OF MY PROJECT AS WELL
// ActionScript file
import com.roguedevelopment.objecthandles.*;

import mx.events.ColorPickerEvent;
public var oh:ObjectHandles = new ObjectHandles();
public var myText:TextArea = new TextArea();
public var maskText:UIComponent = new UIComponent();
public var count:Number = 0;
public var beginIndex:int;
public var endIndex:int;
public var val:int=0;
public var mouse_X:int = 0;
public var mouse_Y:int = 0;
public var point_X:int = 0;
public var point_Y:int = 0;





private function init():void
{
//Setting the properties of Mask

//Setting the properties of TextArea
myText.setStyle("borderStyle","none");
myText.setStyle("fontSize",12);
myText.setStyle("backgroundColor","undefined");
myText.setSelection(beginIndex,endIndex);
myText.wordWrap=true;
myText.height= 40;
myText.width = 150;
myText.editable = false;

//Setting the properties of the object handle
oh.addChild(myText);
oh.x = 150;
oh.y = 280;
oh.enabled = true;
oh.visible = true;
oh.mouseChildren = true;
oh.allowHMove = false;
oh.allowVMove = false;
oh.allowHResize = true;
oh.allowVResize = true;
oh.allowRotate = true;
oh.alwaysMaintainAspectRatio = false;
oh.allowKeyboardManipulation = false;

//Adding event listeners for object resizing
oh.addEventListener(MouseEvent.MOUSE_DOWN,setMouse PointHandler);
oh.addEventListener(MouseEvent.MOUSE_UP,resetMouse PointHandler);
oh.addEventListener //oh.addEventListener(ObjectHandleEvent.OBJECT_RESIZ ING_EVENT,txtResize);
//oh.addEventListener(ObjectHandleEvent.OBJECT_RESIZ ED_EVENT,resizeFont);
this.addEventListener(MouseEvent.MOUSE_OUT,getType );

// Adding object handler to canvas
myCan1.addChild(oh);
}




//Initializing a function to resize the font while resizing the text area:zooming



//Function for transfering the text from one text area to the other text area:trasfer text
private function transferText():void
{
myText.text = myArea.text;
}
//Function for changing the font type of the text
public function changeFont(event:Event):void
{
beginIndex = myArea.selectionBeginIndex;
endIndex = myArea.selectionEndIndex;
var font:String = event.currentTarget.selectedItem.label;
if(beginIndex == endIndex)
{
myText.setStyle("fontFamily",font);
myArea.setStyle("fontFamily",font);
}
else
{
var mySelectedTextRange:TextRange = new TextRange(myText,true,beginIndex,endIndex);
var mySelectedTextRange1:TextRange = new TextRange(myArea,true,beginIndex,endIndex);
mySelectedTextRange.fontFamily = font;
mySelectedTextRange1.fontFamily = font;
}
}

//Function for underlining the text entered
public function check_Line():void
{

var beginIndex:int = myArea.selectionBeginIndex;
var endIndex:int = myArea.selectionEndIndex;
if(beginIndex == endIndex)
{
if(myArea.getStyle("textDecoration") == "underline")
{
myText.setStyle("textDecoration","normal");
myArea.setStyle("textDecoration","normal");
}
else
{
myArea.setStyle("textDecoration","underline");
myText.setStyle("textDecoration","underline");
}
}
else
{
var mySelectedTextRange:TextRange = new TextRange(myText, true,beginIndex,endIndex);
var mySelectedTextRange1:TextRange = new TextRange(myArea, true,beginIndex,endIndex);
if (mySelectedTextRange.textDecoration == "underline")
{
mySelectedTextRange.textDecoration = "normal";
mySelectedTextRange1.textDecoration = "normal";
}
else
{
mySelectedTextRange.textDecoration = "underline";
mySelectedTextRange1.textDecoration = "underline";
}
}
}

//Function for changing the text entered or the text selected into BOLD
public function check_Bold():void
{
var beginIndex:int = myArea.selectionBeginIndex;
var endIndex:int = myArea.selectionEndIndex;
if(beginIndex == endIndex)
{
if(myArea.getStyle("fontWeight") == "bold")
{
myText.setStyle("fontWeight","normal");
myArea.setStyle("fontWeight","normal");
}
else
{
myArea.setStyle("fontWeight","bold");
myText.setStyle("fontWeight","bold");
}
}
else
{
var mySelectedTextRange:TextRange = new TextRange(myText, true,beginIndex,endIndex);
var mySelectedTextRange1:TextRange = new TextRange(myArea, true,beginIndex,endIndex);
if (mySelectedTextRange.fontWeight == "bold")
{
mySelectedTextRange.fontWeight = "normal";
mySelectedTextRange1.fontWeight = "normal";
}
else
{
mySelectedTextRange.fontWeight = "bold";
mySelectedTextRange1.fontWeight = "bold";
}
}
}

//Function for changing the text entered or the text selected into ITALIC
public function check_Italic():void
{
var beginIndex:int = myArea.selectionBeginIndex;
var endIndex:int = myArea.selectionEndIndex;
if(beginIndex == endIndex)
{
if(myArea.getStyle("fontStyle") == "italic")
{
myText.setStyle("fontStyle","normal");
myArea.setStyle("fontStyle","normal");
}
else
{
myArea.setStyle("fontStyle","italic");
myText.setStyle("fontStyle","italic");
}
}
else
{
var mySelectedTextRange:TextRange = new TextRange(myText, true,beginIndex,endIndex);
var mySelectedTextRange1:TextRange = new TextRange(myArea, true,beginIndex,endIndex);
if (mySelectedTextRange.fontWeight == "italic")
{
mySelectedTextRange.fontStyle = "normal";
mySelectedTextRange1.fontStyle = "normal";
}
else
{
mySelectedTextRange.fontStyle = "italic";
mySelectedTextRange1.fontStyle = "italic";
}
}
}



//Funtion for changing the color of the text entered.
private function colorChange(event:ColorPickerEvent):void
{
beginIndex = myArea.selectionBeginIndex;
endIndex = myArea.selectionEndIndex;
var colour:int=event.currentTarget.selectedItem;
if (beginIndex == endIndex)
{
myText.setStyle("color",colour);
myArea.setStyle("color",colour);
}
else
{
var mySelectedTextRange:TextRange = new TextRange(myText,true,beginIndex,endIndex);
var mySelectedTextRange1:TextRange = new TextRange(myArea,true,beginIndex,endIndex);
mySelectedTextRange.color = colour;
mySelectedTextRange1.color = colour;
}
}

//Funtion for changing the font size of the text entered
public function fontSize(event:Event):void
{
beginIndex = myArea.selectionBeginIndex;
endIndex = myArea.selectionEndIndex;
var size:int = parseInt(event.currentTarget.selectedItem.label);
if(beginIndex == endIndex)
{
myText.setStyle("fontSize",size);
myArea.setStyle("fontSize",size);
}
else
{
var mySelectedTextRange:TextRange = new TextRange(myText,true,beginIndex,endIndex);
var mySelectedTextRange1:TextRange = new TextRange(myArea,true,beginIndex,endIndex);
mySelectedTextRange.fontSize = size;
mySelectedTextRange1.fontSize = size;
}
}

//Funtion for erasing the object handles on the screen
public function objectDeselect():void
{
SelectionManager.instance.selectNone();
myText.setStyle("borderStyle","none");
}

//Function for checking whether an image has been selected or not
public function alert():void
{
if(val == 0)
Alert.show(" Select Your Image");
else
transferText();
}

//Function to get the styles of the text entered
public function getType(event:MouseEvent):void
{
var beginIndex:int = myArea.selectionBeginIndex;
var endIndex:int = myArea.selectionEndIndex;
var mySelectedTextRange:TextRange = new TextRange(myArea,true,beginIndex,endIndex);
cf.text = mySelectedTextRange.fontFamily;
cs.text = mySelectedTextRange.fontSize.toString();
if(mySelectedTextRange.color == null)
cp.selectedColor = 0xFFFFFF;
else
cp.selectedColor = mySelectedTextRange.color.toString();
if (mySelectedTextRange.fontWeight == "bold")
b.setStyle("color",0xCCCCCCC);
else if(mySelectedTextRange.fontWeight == "normal")
b.setStyle("color", 000000);
else if(mySelectedTextRange.fontWeight == "null")
b.setStyle("color",0xCCCCCCC);
if (mySelectedTextRange.fontStyle == "italic")
i.setStyle("color",0xCCCCCCC);
else
i.setStyle("color", 000000);
if (mySelectedTextRange.textDecoration == "underline")
u.setStyle("color",0xCCCCCCC);
else
u.setStyle("color", 000000);
}

wvxvw
02-16-2009, 10:59 AM
Did you try the TextArea.htmlText property?

prasanna
02-16-2009, 01:58 PM
Did you try the TextArea.htmlText property?
how to use that