Wednesday, August 4, 2010

Dynamic TextArea And TextInput Resize

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.TextArea;
import mx.controls.Image;
import mx.controls.Label;
import mx.containers.Canvas;
public function init():void
{
var tex:TextArea=new TextArea();
tex.percentHeight=100;
tex.percentWidth=100;
var rCnv:ResizableCanvas = new ResizableCanvas();
rCnv.width = 100;
rCnv.height = 100;
rCnv.setStyle("horizontalCenter", 0);
rCnv.setStyle("verticalCenter", 0);

var inCnv:Canvas = new Canvas();
inCnv.percentWidth = 100;
inCnv.percentHeight = 100;
inCnv.setStyle("cornerRadius",16);
inCnv.setStyle("color",0x777777);
inCnv.setStyle("backgroundColor",0xffffff);
inCnv.setStyle("borderStyle","solid");
inCnv.setStyle("borderThickness",0); 
inCnv.setStyle("borderAlpha",0);
inCnv.setStyle("cornerRadius",16);
inCnv.setStyle("verticalScrollPolicy",'false');
//rCnv.verticalScrollPolicy=false;
rCnv.addChild(inCnv);


                                  rCnv.addChild(tex);
bgcan.addChild(rCnv);

rCnv.minWidth = 80;
rCnv.maxWidth = 800;
rCnv.minHeight = 80;
rCnv.maxHeight = 570;
<-----Call The components--->
var tex2:dynamicresize=new dynamicresize();
tex2.setStyle("horizontalCenter", 0);
tex2.setStyle("verticalCenter", 0);
bgcan0.addChild(tex2)
}

]]>
</mx:Script>
<mx:Canvas id="bgcan" x="124" y="179" width="359" height="429" backgroundColor="white" borderThickness="2" borderStyle="solid" borderColor="black">
<mx:Label x="107.5" y="10" text="TextArea Resize" fontWeight="bold" fontSize="15" textDecoration="underline"/>
</mx:Canvas>
<mx:Canvas id="bgcan0" x="493" y="179" width="359" height="429" backgroundColor="white" borderThickness="2" borderStyle="solid" borderColor="black">
<mx:Label x="104.5" y="10" text="TextInput Resize" fontWeight="bold" fontSize="15" textDecoration="underline"/>
</mx:Canvas>
</mx:Application>
<----------------Automatic TextArea Resize Component------------------>

<?xml version="1.0" encoding="utf-8"?>

<mx:TextArea xmlns:mx="http://www.adobe.com/2006/mxml" htmlText="Welcome to Flex3.0" wordWrap="false" change="onValidation()" verticalScrollPolicy="off" horizontalScrollPolicy="off"
 height="22" width="108" creationComplete="init()" keyDown="onKeyDown(event)" updateComplete="onValidation()">


<mx:Script>
<![CDATA[

import mx.controls.textClasses.TextRange;
private function init():void
{
this.validateNow();
}
private function onValidation():void
{
var metrics:TextLineMetrics = this.getLineMetrics(0);
this.width = this.textWidth + 10;
this.height = this.textHeight + 10;
this.verticalScrollPosition = 0;
this.horizontalScrollPosition = 0;
}

private function onKeyDown(e:KeyboardEvent):void
{
var tr:TextRange = new TextRange(this, true);
if(e.ctrlKey && e.keyCode == 66){
if(tr.fontWeight == "normal"){
tr.fontWeight = "bold";
}
else{ tr.fontWeight = "normal" }
}
if(e.ctrlKey && e.keyCode == 73){
if(tr.fontStyle == "normal"){
tr.fontStyle = "italic";
}
else{ tr.fontStyle = "normal" }
}
if(e.ctrlKey && e.keyCode == 85){
if(tr.textDecoration == "normal"){
tr.textDecoration = "underline";
}
else{ tr.textDecoration = "normal" }
}
}
]]>
</mx:Script>
<mx:StringValidator source="{this}" property="text" minLength="10" valid="onValidation()"/>
</mx:TextArea>

OUTPUT
















No comments:

Post a Comment