No worries mate. Keep in mind I'm typing this in gmail, not flex builder so
it might not be valid code, but it'll be close :)
<mx:Component>
<mx:HBox horizontalAlign="center">
<mx:Script><![CDATA[
protected function redispatch(sourceEvent : Event) : void {
var newEvent : DynamicEvent = new DynamicEvent("aButtonWasClicked",
true);
newEvent["sourceEvent"] = sourceEvent;
dispatchEvent(newEvent);
}
]]></mx:Script>
<mx:Button label="Press Me" click="redispatch(event)"/>
</mx:HBox>
</mx:Component>
Somewhere in your Application you create a function like this:
protected function buttonWasClickedHandler(event : DynamicEvent) : void {
Alert.show("Button was clicked. Source event is : " +
event["sourceEvent"], "Ouch!");
//Do whatever you wanted with the data
doThis(event["sourceEvent"]);
}
And in your handler for creationComplete (for the application), add this:
addEventListener("aButtonWasClicked", buttonWasClickedHandler);
If you're not sure about how any of this works, just let me know and I'll
try explain a little better :D
-J
On Thu, May 22, 2008 at 2:57 PM, timgerr <[EMAIL PROTECTED]> wrote:
> -J,
> I am still learning Flex, can you supply an example on the event way
> you would do this so I can learn from it. I learn better when I can
> see some code.
>
> Thanks for taking the time,
> timgerr
>
>
> --- In [email protected] <flexcoders%40yahoogroups.com>, "Josh
> McDonald" <[EMAIL PROTECTED]> wrote:
> >
> > When you use the <mx:component> tag, it does some voodoo and creates a
> > completely new class for you, extending whatever is the first child
> (in your
> > case, the new class would extend HBox).
> >
> > This class has its own scope, so it doesn't have member access to
> anything
> > in the scope of your existing application.
> >
> > There's a few options for you here:
> >
> > 1) You can call Application.application.doThis(event) - this is
> quick, but
> > not so nice. Not how I'd do it. doThis() must be public or you'll get a
> > run-time error
> >
> > 2) You can do add a function to your custom component that
> dispatches a new
> > event, and listen to the event from your application, you just have
> to put
> > true, for "bubbles" when you instantiate your event. This is how I'd
> do it.
> > You can subclass Event, or just use a DynamicEvent if you want to
> pass extra
> > information up to the application-level handler.
> >
> > And yes, I do have a hard-on for event-based programming. It's the
> right way
> > to do things in most cases :)
> >
> > -J
> >
>
>
>
--
"Therefore, send not to know For whom the bell tolls. It tolls for thee."
:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: [EMAIL PROTECTED]