View Full Version : converting (casting?) TextFormat object from ComboBox
partimer
July 31st, 2008, 11:27 AM
I've a textfield that can have different TextFormats applied to it - these formats are in a combo:
var comboProp:Array = [{label:"Body style 1", data:myFormat1}, {label:"Body Sytle 2", data:myFormat2}, ....etc
The listener function needs to set the TextFormat of the field to the chosen combo value:
field_txt.setTextFormat(ComboBox(evt.currentTarget ).selectedItem.data);
but I'm getting all sorts of errors - notably:
cannot convert "[object TextFormat]" to flash.text.TextFormat.
I've tried appending ....data.getTextFormat() to the end of the above but no joy. I guess this is a simple schoolboy error but if anyone can help I'd most appreciate it!
Cheers,
Pt
partimer
July 31st, 2008, 12:51 PM
ok - so I've found a workaround - not ideal but:
var comboProp:Array = [{label:"Body style 1", data:"1"}, {label:"Body Sytle 2", data:"2"}, ....etc]
Then apply a conditional loop based on the combo value:
if (cmbSize.value == "1") {
field_txt.setTextFormat(myFormat1);
} else if (cmbSize.value == "2") {...etc
Surely there must be a way to pass the TextFormat directly from the combo and apply that format?
partimer
August 1st, 2008, 11:35 AM
ran into the same problem but can find no work-around to this one:
I've a formatted text field - clicking on an edit_btn brings up a text editor and I'm trying to get the existing textfield format properties (and text) into the editor.
The text gets pushed along fine but I'll be damned if I can set the TextFormat:
function highlightTextPanel(evt:MouseEvent):void {
if (toolMode == 1) {
_text_contentText.text = evt.target.text;
_text_content = evt.target.getTextFormat(0);
editBTN1.buttonMode = true;
editBTN1.addEventListener(MouseEvent.CLICK,texterE ditor);
}
}
}
function texterEditor(evt:Event):void {
removeEventListener(MouseEvent.CLICK,texterEditor) ;
textEditor.visible = true;
textEditor.field_txt.text = _text_contentText.text;
trace(_text_content.getTextFormat(0) + " text format object"); // outputs '[object TextFormat] text format name' - so the text format object is being passed?
textEditor.field_txt.setTextFormat(_text_content.g etTextFormat()); // throws error: 1061: Call to a possibly undefined method getTextFormat through a reference with static type flash.text:TextFormat.
}
Please can someone tell what I'm doing wrong here!?!
partimer
August 1st, 2008, 12:33 PM
doh...
textEditor.field_txt.setTextFormat(_text_content);
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.