I'm getting a compiler message saying "Event
type 'events.CustomEvent' is unavailable", and I don't understand
why. I'm hoping a second eye might catch the problem.
My custom event class is called CustomEvent.as: (the dao.Person class
is just a dummy class that stores a firstName, middleName, and
lastName, and I was going to see if the data in this object will be
available in my 'testEvent' handler).
package actionscript
{
import dao.Person;
import flash.events.Event;
public class CustomEvent extends Event
{
public var person:Person;
public function CustomEvent(person:Person,
type:String)
{
super(type);
this.person = person;
}
public override function clone():Event
{
return new CustomEvent(person, type);
}
}
}
I'm trying to dispatch the above custom event from a test component
called TestComponent.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:TextInput xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Metadata>
[Event(name="testEvent", type="events.CustomEvent")]
</mx:Metadata>
<mx:Script>
<![CDATA[
import actionscript.CustomEvent;
import dao.Person;
public function fireAway():void
{
var p:Person = new Person
("John", "Missing", "Doe");
var e:CustomEvent = new CustomEvent
(p, "testEvent");
this.dispatchEvent(e);
}
]]>
</mx:Script>
</mx:TextInput>
And finally, here is my MXML application that's supposed to test all
this and is called CustomEventsTest.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
xmlns:c="components.*">
<mx:Script>
<![CDATA[
import actionscript.CustomEvent;
import components.TestComponent;
private function clickHandler():void
{
testComponent.fireAway();
}
private function testEventHandler
(event:CustomEvent):void
{
trace("It got here to testEventHandler.");
}
]]>
</mx:Script>
<mx:VBox>
<!-- ***************************** -->
<c:TestComponent id="testComponent"
backgroundColor="yellow"
testEvent="testEventHandler(event)"/>
<!-- ***************************** -->
<mx:Button id="btnFireEvent"
label="Fire Event"
click="clickHandler()"/>
</mx:VBox>
</mx:Application>
The compiler error message is complaining about the c:TestComponent
between the two lines of asterisks. Can anyone see why the compiler
is telling me
why CustomEvent is unavailable?
Thanks in advance for your time.