views:

83

answers:

2

printableInvoice.addEventListener(batchGenerated, printableInvoice_batchGeneratedHandler);

Results in this error: 1120: Access of undefined property batchGenerated. I have tried it as FlexEvent.batchGenerated and FlashEvent.batchGenerated.

The MetaData and function that dispatches the even in the component printableInvoice is all right. It I instantiate printableInvoice as an mxml component instead of via action-script it well let put a tag into the mxml line: batchGenerated="someFunction()"

Thanks.

+1  A: 

batchGenerated should be a string.

sharvey
batchGenerated="foo()" in mxml is flex compiler magic. When you are in an AS file, you need to use the string representation of the event.
sharvey
A: 

It looks like your application dispatches an event whenever the batch is generated.

I'm assuming inside your code you have something along the lines of either:

dispatchEvent( new BatchEvent("batchGenerated") );

or

dispatchEvent( new BatchEvent(BatchEvent.BATCH_GENERATED) );

The second way is usually preferred as using variables instead of magic strings gives you an extra level of compile time checking.

The first required parameter of events is typically the type of the event - Event.CHANGE (aka "change"), FlexEvent.VALUE_COMMIT (aka "valueCommit") etc.

This is what the event listener is actually comparing against.

So in your event listener code above, you would want to change the line to be either:

printableInvoice.addEventListener("batchGenerated", printableInvoice_batchGeneratedHandler);

or hopefully

printableInvoice.addEventListener(BatchEvent.BATCH_GENERATED, printableInvoice_batchGeneratedHandler);

If you want to go further, the Flex documentation goes into some detail as to how the event system works, and how the events are effectively targeted and handled through the use of the Capture, Target, and Bubble phases.

merlinc