4 Replies Latest reply on Mar 6, 2009 6:05 AM by Newsgroup_User

    Passing a parameter with a custom event?

    Handycam Level 1
      OK, I almost have this figured out, but there's still one part that escapes me.

      I have a component that is going to dispatch a custom event "ImageClicked" (see code). The component instance has a string variable "var link:String". I pass a link string to this component when it is created, for example purposes, let's say the value is " http://www.adobe.com".

      I want to fire this event to the main application, and pas the value of "link" along with the event, so my application would then go to Adobe's home page (in this example).

      I then have this event listener: mainStack.addEventListener(ImageClicked.CLICK, goLink);

      My goLink function expects a string parameter, the value of "link" in the component, in this case I'd want it to be " http://www.adobe.com".

      Can someone please clear this up for me? I feel like I am so close, but missing a key ingredient
        • 1. Re: Passing a parameter with a custom event?
          Handycam Level 1
          OK, to clarify things a bit, I have changed the name of the variable in the component to "linkStr".

          When I create the component, I am assigning the value to that variable, from XML nodes:

          var slideUnit:Slide = new Slide();
          mainStack.addChild(slideUnit);
          slideUnit.slideTitle.text = slide.title;
          slideUnit.slideText.text = slide.caption;
          slideUnit.slideImage.source = slide.image;
          slideUnit.linkStr = slide.link; //<-- HERE

          I am assuming my problem is connecting linkStr in the component with th var in the event, right? How does one do that?

          Right now, if I trace the data being returned by the event I get:
          [Event type="imageClicked" bubbles=true cancelable=false eventPhase=3]

          Not any string.

          • 2. Re: Passing a parameter with a custom event?
            John Hall Level 4
            Here's one approach. Let us know if this doesn't work in your situation.
            • 3. Re: Passing a parameter with a custom event?
              Handycam Level 1
              Yes, John, thank you very much.
              The key thing I did not grasp or forgot to do was:

              myCustomEvent.link = " http://www.adobe.com"

              THAT is how I assign the variable in the event. It should have been obvious to me, but it wasn't. And all the examples I find on line go into very complicated apps, and I thank you for keeping your code example focused on the issue at hand.

              I just changed it in my app to myCustomEvent.link = linkStr and the listener handler to:

              private function goLink(w:ImageClicked):void {
              var url:URLRequest = new URLRequest(w.link);
              navigateToURL(url,"_self");
              }

              Awesome, thanks again!
              • 4. Re: Passing a parameter with a custom event?
                Level 7

                "Handycam" <webforumsuser@macromedia.com> wrote in message
                news:gop046$s2l$1@forums.macromedia.com...
                > OK, I almost have this figured out, but there's still one part that
                > escapes me.
                >
                > I have a component that is going to dispatch a custom event "ImageClicked"
                > (see code). The component instance has a string variable "var
                > link:String".
                > I pass a link string to this component when it is created, for example
                > purposes, let's say the value is " http://www.adobe.com".

                You're not giving your ImageClicked any new information, so you don't need a
                custom event http://flexdiary.blogspot.com/2007/08/dispatching-events.html

                Your component already has a public property link. Just read that off of
                event.currentTarget.

                HTH;

                Amy