Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add getter and setter for TextField and TextFormat properties #67

Merged
merged 1 commit into from

2 participants

@Svenito

Added the getter and setter as per #50

not 100% sure about the getter as the fail case returns null which is a valid value for some properties. Might not even need a getter anyway.

@Draknek
Collaborator

Thanks!

The getter could throw an exception if the property doesn't exist, though I don't really think that's necessary.

@Svenito

If the getter throws an exception then the setter should too. Would be the best way to handle this, but it's up to you if you think that's necessary.

@Draknek Draknek merged commit 3ff6736 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 31 additions and 0 deletions.
  1. +31 −0 net/flashpunk/graphics/Text.as
View
31 net/flashpunk/graphics/Text.as
@@ -470,6 +470,37 @@
*/
public function get textHeight():uint { return _textHeight; }
+ /**
+ * Set TextField or TextFormat property
+ * returns true on success and false if property not found on either
+ */
+ public function setTextProperty(name:String, value:*):Boolean {
+ if (_field.hasOwnProperty(name)) {
+ _field[name] = value;
+ } else if(_form.hasOwnProperty(name)) {
+ _form[name] = value;
+ _field.setTextFormat(_form);
+ } else {
+ return false;
+ }
+ updateTextBuffer();
+ return true;
+ }
+
+ /**
+ * Get TextField or TextForm property
+ */
+ public function getTextProperty(name:String):* {
+ if (_field.hasOwnProperty(name)) {
+ return _field[name];
+ } else if(_form.hasOwnProperty(name)) {
+ return _form[name];
+ } else {
+ // TODO need a better "cannot get" value here
+ return null;
+ }
+ }
+
// Text information.
/** @protected */ protected var _field:TextField = new TextField;
/** @protected */ protected var _width:uint;
Something went wrong with that request. Please try again.