tx Mayur its a very nice and helpful example
But i need some more help in this
Please check out with the following code:
<?xml version="1.0"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
import flash.text.TextField;
import mx.controls.Alert;
use namespace mx_internal;
// the namespace is used as the getTextField() etc method is
not available in the default namespace...
public function makeBold():void{
// makes the selected text from textField bold
var tf:TextFormat = new TextFormat();
var beginIndex:int =
myText.getTextField().selectionBeginIndex;
var endIndex:int =
myText.getTextField().selectionEndIndex;
tf.bold = true
Alert.show(beginIndex+"::::"+endIndex)
myText.getTextField().setTextFormat(tf,beginIndex,endIndex);
}
public function makeItalic():void{
// makes the selected text from textField bold and red
var tf:TextFormat = new TextFormat();
var beginIndex:int =
myText.getTextField().selectionBeginIndex;
var endIndex:int =
myText.getTextField().selectionEndIndex;
tf.italic = true
myText.getTextField().setTextFormat(tf,beginIndex,endIndex);
}
public function makeUnderline():void{
// makes the selected text from textField bold and red
var tf:TextFormat = new TextFormat();
var beginIndex:int =
myText.getTextField().selectionBeginIndex;
var endIndex:int =
myText.getTextField().selectionEndIndex;
tf.underline = true
myText.getTextField().setTextFormat(tf,beginIndex,endIndex);
}
public function makeleftAlign():void{
// Aligns the text of whole text Area
var tf:TextFormat = new TextFormat();
var beginIndex:Number =
myText.getTextField().getFirstCharInParagraph(beginIndex)-1;
beginIndex = Math.max(0, beginIndex);
var endIndex:Number =
myText.getTextField().getFirstCharInParagraph(endIndex)
+myText.getTextField().getParagraphLength(endIndex)-1;
tf.align= "left";
myText.getTextField().setTextFormat(tf);
}
public function makerightAlign():void{
// Aligns the text of whole text Area
var tf:TextFormat = new TextFormat();
var beginIndex:Number =
myText.getTextField().getFirstCharInParagraph(beginIndex)-1;
beginIndex = Math.max(0, beginIndex);
var endIndex:Number =
myText.getTextField().getFirstCharInParagraph(endIndex)
+myText.getTextField().getParagraphLength(endIndex)-1;
tf.align= "right";
myText.getTextField().setTextFormat(tf);
}
public function makecenterAlign():void{
// Aligns the text of whole text Area
var tf:TextFormat = new TextFormat();
var beginIndex:Number =
myText.getTextField().getFirstCharInParagraph(beginIndex)-1;
beginIndex = Math.max(0, beginIndex);
var endIndex:Number =
myText.getTextField().getFirstCharInParagraph(endIndex)
+myText.getTextField().getParagraphLength(endIndex)-1;
tf.align= "center";
myText.getTextField().setTextFormat(tf);
}
public function wordwrap():void{
myText.wordWrap=true;
}
[Bindable]
public var fonts: Array = [ {label:"Arial",
data:"Arial"},
{label:"Verdana", data:"Verdana"}];
[Bindable]
public var sizes: Array = [ {label:"8", data:1},
{label:"9", data:2}, {label:"10", data:3} ];
public function setFontColor(col):void{
// Aligns the text of whole text Area
var tf:TextFormat = new TextFormat();
var beginIndex:Number =
myText.getTextField().getFirstCharInParagraph(beginIndex)-1;
beginIndex = Math.max(0, beginIndex);
var endIndex:Number =
myText.getTextField().getFirstCharInParagraph(endIndex)
+myText.getTextField().getParagraphLength(endIndex)-1;
tf.color= col;
myText.getTextField().setTextFormat(tf);
}
public function setBgColor(col):void{
// myText.backgroundColor=col;
}
]]>
</mx:Script>
<mx:Button y="170" id="b2" label="make me Italic"
click="makeItalic()" x="474"/>
<mx:Button y="170" id="b1" label="make me Underline"
click="makeUnderline()" x="594"/>
<mx:Button y="170" id="b5" label="make me Bold"
click="makeBold()" x="354"/>
<mx:Button y="89" id="b6" label="wordwrap" click="wordwrap()"
x="494"/>
<mx:ComboBox x="479" y="203" dataProvider="{fonts}"
change="setFontColor(event.target.selectedItem)"/>
<mx:ComboBox x="546" y="203" dataProvider="{sizes}"
change="setBgColor(event.target.selectedItem)"/>
<mx:Button id="b3" label="make me leftAlign"
click="makeleftAlign()" y="242" x="333"/>
<mx:Button id="b0" label="make me rightAlign"
click="makerightAlign()" y="242" x="472"/>
<mx:Button id="b4" label="make me centerAlign"
click="makecenterAlign()" y="242" x="618"/>
<mx:Label text="Type here the text and/or select the text here and
click respective button" x="333" y="272"/>
<mx:TextArea height="232" textAlign="center" id="myText" x="444"
y="298" />
<mx:ColorPicker x="503" y="123" toolTip="text color"/>
<mx:ColorPicker x="546" y="123" toolTip="background color">
</mx:ColorPicker>
</mx:Application>
lets say when user enters an application and he wants his text of red
color and he selects red from color picker then i want to set the
color in text format as red and same for every other feature of text
format.
how to implement defaultTextFormat in this?
i want a same toolbar as MS-Excel's toolbar..
On Jul 16, 3:09 am, "Mayur Bais" <
mayur.b...@...> wrote:
> Hi ,
>
> See if the following code snippet solves your problem. Let me know if you
> face any issues.
>
> <?xml version="1.0"?>
> <!-- styles/runtime/BasicApp.mxml -->
> <mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml">
>
> <mx:Script>
> <![CDATA[
> import mx.core.UIComponent;
> use namespace mx_internal;
> // the namespace is used as the getTextField() etc method is not
> available in the default namespace...
>
> function makeBold(){
>
> // makes the selected text from textField bold
> var tf:TextFormat = new TextFormat();
> var beginIndex:int = myText.getTextField().selectionBeginIndex;
> var endIndex:int = myText.getTextField().selectionEndIndex;
> tf.bold = true
> myText.getTextField().setTextFormat(tf,beginIndex,endIndex);
> }
>
> function makeBoldAndBlue(){
>
> // makes the selected text from textField bold and red
> var tf:TextFormat = new TextFormat();
> var beginIndex:int = myText.getTextField().selectionBeginIndex;
> var endIndex:int = myText.getTextField().selectionEndIndex;
> tf.bold = true
> tf.color = "0xe50f0f"
> myText.getTextField().setTextFormat(tf,beginIndex,endIndex);
> }
>
> function makeleftAlign(){
> // Aligns the text of whole text Area
> var tf:TextFormat = new TextFormat();
> var beginIndex =
> myText.getTextField().getFirstCharInParagraph(beginIndex)
> - 1;
> beginIndex = Math.max(0, beginIndex);
> var endIndex =
> myText.getTextField().getFirstCharInParagraph(endIndex)
> +
> myText.getTextField().getParagraphLength(endIndex) - 1;
> tf.align= "left";
> myText.getTextField().setTextFormat(tf);
> }
> ]]>
>
> </mx:Script>
>
> <mx:Button id="b1" label="make me Bold " click="makeBold()"/>
> <mx:Button id="b2" label="make me Bold and red"
> click="makeBoldAndBlue()"/>
> <mx:Button id="b3" label="make me leftAlign" click="makeleftAlign()"/>
> <mx:Label text="Type here the text and/or select the text here and click
> respective button" />
> <mx:TextArea textAlign="center" id="myText" height="254" text="Virus
> hunters at Symantec have stumbled upon a malicious server using an attack
> framework that intelligently chooses exploits based on the client's browser.
> Here's a blow-by-blow of the attack. "/>
>
> </mx:Application>
>
> Regards!
>
> On 7/15/07, kanu <
kanukukr...@...> wrote:
>
>
>
>
>
> > i have a text field
>
> > in which from character 1-9 its bold italic and with blue color
>
> > character 12-14 some different properties
>
> > but now if i'm selecting align center then it automatically changes
> > the color of whole text according to selected color.
>
> > in getTextFormat () method
>
> > its written:
>
> > Any property that is mixed, meaning that it has different values at
> > different points in the text, has a value of null.
>
> > is there is any method to solve this problem.- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Flex India Community" group.
To post to this group, send email to
flex_india@...
To unsubscribe from this group, send email to
flex_india-unsubscribe@...
For more options, visit this group at
http://groups.google.com/group/flex_india?hl=en-~----------~----~----~----~------~----~------~--~---