Shan’s Simple Examples: Extending an object in Actionscript
The other day, someone asked me how they could re-use the code sample from Igor Costa’s post about getting the Rich Text Editor to output XHTML. Whenever you want to add functionality to an existing control, you just need to extend it. Here’s how:
Here’s the top bit of code from my XHtmlEditor.as file:
1 2 3 4 5 6 7 8 9 10 | package org.iotashan.controls { import mx.controls.RichTextEditor; public class XHtmlEditor extends mx.controls.RichTextEditor { public function XHtmlEditor() { super() } |
The actual code where I’m telling the compiler that this object extends RichTextEditor is line 5. You can then see that in the constructor method, I call super() on line 9. The super() method just calls the original constructor of the RichTextEditor object.
From here, we define a getter and setter method for a property called xhtml. The xhtml property doesn’t actually store any value in our object, we just use it as an interface to the convertToXHtml() and convertFromXHtml() methods from Igor’s blog post.
12 13 14 15 16 17 18 |
You can view the full working example here, and get the source here.
