views:

27

answers:

1

Well there is two issues with the code below. Help with either of them would be greatly appreciated.

The first issue is that it doesn't like "(t.attribute==true)". It doesn't seem like me using a variable in that way. Are there any ways of getting around this?

The second issue, is again with the same variable, "("un" + attribute)", I really have no clue how to code this bit correctly.

//this is what calls it.

TextFormatCreator(bold, begin, end, tf);

//this is an extract from where the issue is. attribue is bold/italic/underline. begin and end are the parameters of the highlighted text. tf is the textformat.

private var enbold:TextFormat = new TextFormat();
  private var unbold:TextFormat = new TextFormat();
  private var enitalic:TextFormat = new TextFormat();
  private var unitalic:TextFormat = new TextFormat();
  private var enunderline:TextFormat = new TextFormat();
  private var ununderline:TextFormat = new TextFormat();

  public function TextFormatCreator(attribute:String, begin:int, end:int, tf:JTextArea)
  {
   setBase()
   begin=tf.getSelectionBeginIndex();
   end=tf.getSelectionEndIndex();

   var t:TextFormat=tf.getTextFormat(begin,end);
   if (t.attribute==true) {
    tf.setTextFormat(("un" + attribute), begin, end);
   }
   if (t.attribute==false) {
    tf.setTextFormat(("en" + attribute), begin, end);
    tf.setTextFormat(enbold, begin, end);
   }
   if (t.attribue==null) {
    tf.setTextFormat(("en" + attribute), begin, end); 
   }
  }
A: 

Please review the TextFormat API as phwd stated is does not have any "attirbute" property. Also it is allways advice to check wheter t is null or undefined before you start accessing properties in it.

Dudi