Search code examples
apache-flexadobemxml

how to call java method from actionscript


I've just now started working on Flex. May be its basic question but I’m not aware of it – how can I call a java method from actionscript. I want to call some java method on double click of a event. Can you please let me know how to proceed on this?


Solution

  • In Flash Builder, under the Data menu, there are data service wizards:

    data-services

    These wizards auto-generate code and are convenient for connecting to WSDL:

    wsdl

    Or HTTP Services:

    http-service

    Accessing data services overview has example implementations, such as this example calling a restaurant web service with responder returning value objects from service.

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/halo"
                   xmlns:employeesservice="services.employeesservice.*"
                   xmlns:valueObjects="valueObjects.*">
    
        <fx:Declarations>
            <s:WebService id="RestaurantSvc"
                          wsdl="http://examples.adobe.com/flex3app/restaurant_ws/RestaurantWS.xml?wsdl" />
            <s:CallResponder id="getRestaurantsResult"
                             result="restaurants = getRestaurantsResult.lastResult as Restaurant" />
        </fx:Declarations>
    
        <fx:Script>
            <![CDATA[
                import mx.controls.Alert;
    
                protected function b1_clickHandler(event:MouseEvent):void
                {
                    getRestaurantsResult.token = RestaurantWS.getRestaurants();
                }
            ]]>
        </fx:Script>
    
        <s:Button id="b1"
                  label="GetRestaurants"
                  click="button_clickHandler(event)" />
    
    </s:Application>
    

    References: