4 Replies Latest reply: Jul 9, 2012 1:13 PM by Ricardo Romero RSS

Trigger an event from WD to Flex

Ricardo Romero
Currently Being Moderated

Hi,

 

I've just started to learn Flash Islands.

I've watched some tutorials by Thomas Jung in wich I've seen how to trigger an event from the Flex application to be handled in the WD application. But I want to do the opposite, I mean trigger an event from the WD to be handled in the Flex side.

 

Is it possible? Do you know how or You know some manual that explains how to do it?

 

Thanks in advance,

Ricardo.

  • Re: Trigger an event from WD to Flex
    Thomas Jung
    Currently Being Moderated

    Any server side event which changes data in the bound context node to the Island can be a way of sending an event into the Island.  Sometimes people will create a context node/attributes just to be event identifiers. 

    • Re: Trigger an event from WD to Flex
      Ricardo Romero
      Currently Being Moderated

      Hi Thomas, Thanks for answer.

       

      I'm trying to do it, but by the moment doesn't work.

       

      I've created a Flex component with a bindable var bounded with an attribute of the WD context.

      I've created also a button UI element and when this button is pushed I change the value of this attribute.

       

      Now I'm trying to subscribe to the event is triggered when I change the context, but I don't know the event type. I guess I need to use the method addEventListener. I'm a newbie with flex and actionscript so if I'm wrong let me know please.

       

      This is my Flex code. The Flex debugger works fine I've put some break-points in the method initApp() and stops there, but not when I push the button in my WD component.

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()">
          <mx:Script>
                    <![CDATA[
                                    import mx.rpc.soap.SOAPFault;
                                    import sap.FlashIsland;
                                    import mx.collections.ArrayCollection;
                                    import mx.controls.Alert;
                                    import flash.events.Event;
                                    import flash.events.ActivityEvent; 
                                    [Bindable]
                                              public var myEvent:String;
                              private function initApp():void
                              {
                                        FlashIsland.register(this);
                                        addEventListener(Event.CHANGE, performAction);
                                        addEventListener(ActivityEvent.ACTIVITY, performAction);
                                        addEventListener(flash.events.DataEvent.DATA, performAction);
                              }
                         public function performAction(event:Event):void {
                                   Alert.show("Event 1 triggered");
                         }
                    ]]>
          </mx:Script> 
      </mx:Application>

       

      Do you know what kind of event I need to use? or how can I do it? if you have a link with a sample code will be very useful.

       

      Thanks!

       

      event.jpg

      • Re: Trigger an event from WD to Flex
        Thomas Jung
        Currently Being Moderated

        There is no direct event registered, since you are only updating bound data. However if you want to perform some action on data change to bound context attributes, then I would suggest using GETTER/SETTERs instead of binding directly to a variable. I do have an example of this, but at the moment SCN seems to be having problems and is asking for user name and password (which don't work) in order to view this document:

        http://scn.sap.com/docs/DOC-2273

        • Re: Trigger an event from WD to Flex
          Ricardo Romero
          Currently Being Moderated

          Hi Thomas,

           

          I've seen you have fixed the problem with the password of the video. I've already watched the video and I'm trying to use the setters to do something in the Flex component when in push a button in my WD component.

          But the setter is triggered with any event in my WD component not only for the property bound.

           

          What I did is the following:

           

          - I've created a context node with an attribute to be bound with the setter in the Flex component.

          - I've created a button in my WD component and when is pushed I change the value of the attribute in the context.

          - I've created another 'Dummy' button without code only for trigger an event.

          - I've bound the property of the setter with this attribute in the flash island view.

           

          WD_Islands.jpg

           

          This is my Flex code:

           

          <?xml version="1.0" encoding="utf-8"?>  
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()">  
              <mx:Script>  
                <![CDATA[
                           import mx.rpc.soap.WebService;  
                          import mx.rpc.soap.SOAPFault;  
                          import sap.FlashIsland;  
                          import mx.collections.ArrayCollection;  
                          import mx.controls.Alert;  
                            
                      private var initbutton_1:String;
                           
                      private function initApp():void  
                      {  
                           FlashIsland.register(this);
                           initbutton_1 = "X";
                      }  
            
                                public function set Button1(val:Object):void{
                                           if (initbutton_1 == " "){ //to void the first time when the application is initialized
                                 Alert.show("Button 1 pushed");
                       }
                       if (initbutton_1 == "X"){ initbutton_1 = " "; }  
                                }      
                                                            
                ]]>  
              </mx:Script>   
          </mx:Application>  

           

           

          When I push my button "Button1" the setter is triggerd, it's ok.

          The problem is when I push the "Dummy" button the setter is also triggered, and that's wrong.

           

          button1.jpg

           

          Do you know what I'm doing wrong ?


          Thanks in advance,

          Ricardo.

Actions