Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-18-2012, 06:03 PM   #1
jimmi
Quadradius.com creator
 
Join Date: Apr 2005
Location: Boston, Massachusetts, US
Posts: 22
Send a message via AIM to jimmi
Default setTextFormat overrides defaultTextFormat if you set the last character of a field

We are taught that the difference between the defaultTextFormat property and setTextFormat method, is that setTextFormat is only used to change text already in the textfield (with an optional character range specified), while defaultTextFormat is what any new text that is added to the textField will use. There is one gotcha however, and that is if you change the last character of a textfield with setTextFormat, defaultTextFormat will no longer be used.

ActionScript Code:
var textField:TextField = new TextField(); textField.width = 500; addChild(textField); textField.text = "small LARGE "; var defaultTextFormat:TextFormat = new TextFormat(); var adjustedTextFormat:TextFormat = new TextFormat(); defaultTextFormat.size = 10; adjustedTextFormat.size = 20; textField.defaultTextFormat = defaultTextFormat; textField.setTextFormat(adjustedTextFormat, 5, 11);// works as expected //textField.setTextFormat(adjustedTextFormat, 5, 12);// gotcha! textField.appendText(" new text");

What you get with the first version is:
small LARGE new text

What you get with the second version is:
small LARGE new text

All I changed was the endIndex from 11 to 12, and now the textField.appendText will no longer work as advertised. If you are typing in a wordprocessor and you change the font of the last character, this outcome is expected. Having your wordprocessor remember your last font choice is helpful. When I was coding this however, I did not expect this edge case scenario to perform this way.

Something to keep in mind as you are trying to learn the difference between setTextFormat, and defaultTextFormat. Adobe's definition's hold true, until you tamper with the last character.
jimmi is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:30 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.