PDA

View Full Version : Creating components using actionscript


salim_designer
11-28-2007, 07:02 AM
I just tried Flex help to create a component using Actionscript. I found a code which creates a textArea, where if we press control+z the textArea will be empty

Here is the class file:

package myComponents
{
// myComponents/DeleteTextArea.as
import mx.controls.TextArea;
import flash.events.KeyboardEvent;

public class DeleteTextArea extends TextArea {

// Constructor
public function DeleteTextArea() {
// Call super().
super();

// Add event listener for keyDown event.
addEventListener("keyDown", myKeyDown);
}

// Define private keyDown event handler.
private function myKeyDown(eventObj:KeyboardEvent):void {
// Check to see if Ctrl-Z pressed. Keycode for Z is 90.
if (eventObj.ctrlKey && eventObj.keyCode == 90)
text = "";
}
}
}


Here is the file that I am using the component:

<?xml version="1.0"?>
<!-- MainDeleteTextAreaProps.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">

<MyComp:DeleteTextArea wordWrap="true" text="My Message"/>

</mx:Application>


I don't know why the code is not working nor I am getting any error

kifah
11-28-2007, 02:49 PM
Dear Salim,
try this
replace the keydownevent with keyupEvent
addEventListener(KeyboardEvent.KEY_UP, myKeyDown);
instead of
addEventListener("keyDown", myKeyDown);
in your
DeleteTextArea Class

I test this and it's working without error messages...

Regards...

salim_designer
11-29-2007, 05:08 AM
Great!! It's working fine. But I can not figure it out why it is not working with keydown event. Thank you so much :)