3 Replies Latest reply on Dec 28, 2008 9:20 AM by rtalton

    Common Function?

    WestSide Level 1
      Hi,

      I am trying to find a way to have a function that can be called by different view components. How can I do this? If I put the function in the same view component it works fine, but if I create another view component, I can't call the same function even if I make it public.

      public static const SHOW_DETAIL:String = "showDetail";

      public function doSomething(event:MouseEvent):void {
      dispatchEvent( new Event( SHOW_DETAIL ) );
      }

      I am really just looking for a way to mimic traditional javascript file in the header of an HTML page. You can put a function there and call it from any page. I don't want to have the same function in multiple views.

      Any help appreciated..

      -Westside
        • 1. Re: Common Function?
          rtalton Level 4
          You can define a custom event in an actionscript file, then you can call it from anywhere in your application. You can even add extra data to be attached with the custom event.
          If you are defining a custom event in an MXML component, do this:
          • 2. Re: Common Function?
            Level 7

            "rtalton" <webforumsuser@macromedia.com> wrote in message
            news:gj6rj5$q50$1@forums.macromedia.com...
            > You can define a custom event in an actionscript file, then you can call
            > it
            > from anywhere in your application. You can even add extra data to be
            > attached
            > with the custom event.
            > If you are defining a custom event in an MXML component, do this:
            >
            >
            > <mx:Metadata>
            > [Event(name="SHOW_DETAIL", type="flash.events.Event")]
            > </mx:Metadata>
            >
            > dispatchEvent(new Event('SHOW_DETAIL'));

            The other side of that is that your main application should listen for this
            event and call the function you want to have run as a result.


            • 3. Re: Common Function?
              rtalton Level 4
              Good morning Amy!