如何从actionscript调用java方法

时间:2013-05-14 00:38:19

标签: flex adobe mxml

我刚刚开始研究Flex。可能是它的基本问题,但我不知道它 - 如何从actionscript调用java方法。我想在双击事件时调用一些java方法。你能告诉我如何继续这个吗?

1 个答案:

答案 0 :(得分:1)

在Flash Builder的 Data 菜单下,有数据服务向导:

data-services

这些向导自动生成代码,便于连接到WSDL:

wsdl

或HTTP服务:

http-service

Accessing data services overview有示例实现,例如调用餐厅Web服务,响应者从服务返回值对象。

<?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>

参考文献: