从webservice actionscript中读取对象

时间:2015-01-13 07:00:17

标签: web-services actionscript-3 object

我需要读取对象并将它们保存在数组中。我在c#上做到了这一点,但无法弄清楚如何在动作脚本上做到这一点。

c#示例:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestingWSDLLOad.ServiceReference2;

namespace TestingWSDLLOad
{
    class Program
    {



        static void Main(string[] args)
        {
            ServiceReference2.Service1Client testas = new ServiceReference2.Service1Client();
            SortedList<int, PlayListItem> playList = new SortedList<int, PlayListItem>();
            int cc = 0;
            foreach (var resultas in testas.GetPlayList(394570))
            {

                PlayListItem ss = new PlayListItem(resultas.Id, resultas.VideoId, resultas.Path);
                playList.Add(cc, ss);
                cc++;

            }


            Console.WriteLine(playList[0].Id);


            Console.ReadKey();
        }
    }

    public class PlayListItem
    {
        public int VideoId { get; private set; }
        public string Path { get; private set; }
        public int Id { get; private set; }


        public PlayListItem(int id, int videoId, string path)
        {
            Id = id;
            VideoId = videoId;
            Path = path;
        }

    }
}

我知道如何使用actionscript从wsdl获取一个简单的结果,但不知道如何使用参数来获取对象并保存它们。

Service有一个方法GetPlaylist(int value),它返回一个对象数组(id,videoId,path)。如何处理并保存它们?

Here is my as3:

package {


    public class data extends CasparTemplate {

        var flvControl:FLVPlayback;
        var refreshTimer:Timer;

        var videoList:Array;
        var videoNew:Array;

        var videoMaxIds:Array;
        var videoNewMaxIds:Array;

        var videoIndex:uint;
        var videoIdFrom:uint;

        var loopAtEnd:Boolean;

        var _playListItems:Array;
        var _playList:PlayListItem;
        var gotNewPlaylist:Boolean;

        var webService:WebService;
        var serviceOperation:AbstractOperation;

        public function data() 
        {
            _playListItems = new Array();
            flvControl = new FLVPlayback();
            videoNew = new Array();
            videoNewMaxIds = new Array();
            videoIndex = 0;
            videoIdFrom = videoMaxIds[videoIndex];

            loopAtEnd = true;
            gotNewPlaylist = false;

            refreshTimer = new Timer(20000);
            refreshTimer.addEventListener(TimerEvent.TIMER, getNewPlaylist);
            refreshTimer.start();

            flvControl.addEventListener(VideoEvent.COMPLETE, completeHandler);
            flvControl.addEventListener(VideoEvent.STATE_CHANGE, vidState);
            flvControl.setSize(720, 576);
            flvControl.visible = true;
            //addChild(flvControl);

            var url:String = "http://xxx/yyy.svc?wsdl";
            webService = new WebService();
            webService.loadWSDL(url);
            webService.addEventListener(LoadEvent.LOAD, BuildServiceRequest);

        }

        function BuildServiceRequest(evt:LoadEvent):void
        {

            webService.removeEventListener(LoadEvent.LOAD, BuildServiceRequest);

            //serviceOperation.addEventListener(ResultEvent.RESULT, displayResult);

            for (var resultas in webService.getOperation("GetPlaylist(394575)"))
            {
                 trace(resultas.Id);
            }
            //serviceOperation = webService.getOperation("GetPlaylist");
            //serviceOperation.arguments[{videoId: "394575"}];

        } 

        private function displayResult(e:ResultEvent):void
        {
            trace("sss");
        }



        // Handle the video completion (load the next video)
        function completeHandler(event:VideoEvent):void
        {
           if (gotNewPlaylist)
           {
               videoList = videoNew;
               videoMaxIds = videoNewMaxIds;

               videoNew = null;
               videoNewMaxIds = null;
               gotNewPlaylist = false;
               videoIndex = 0;
           } else
             videoIndex++;

           nextVideo();
        }

        private function vidState(e:VideoEvent):void {

            var flvPlayer:FLVPlayback = e.currentTarget as FLVPlayback;
            if (flvPlayer.state==VideoState.CONNECTION_ERROR)   {
                trace("FLVPlayer Connection Error! -> path : "+flvPlayer.source);
                videoIndex++;
                nextVideo();
            } else if (flvPlayer.state==VideoState.DISCONNECTED)    {
                videoIndex++;
                nextVideo();
            }
        }

        function nextVideo():void
        {   
            trace("Video List:"+videoList.toString());
            if( videoIndex == videoList.length ){
               if( loopAtEnd )
               {
                    videoIndex = 0;
               } else { return; }
           }

           flvControl.source = videoList[videoIndex];
           if (videoIdFrom < videoMaxIds[videoIndex])
                videoIdFrom = videoMaxIds[videoIndex];
           trace(videoIdFrom);  
        }

    }
}

internal class PlayListItem
{
    private var _videoId:int;
    private var _path:String;
    private var _id:int;

    public function get VideoId():int { return _videoId; }
    public function get Path():String { return _path; }
    public function get Id():int { return _id; }

    public function set VideoId(setValue:int):void { _videoId = setValue };
    public function set Path(setValue:String):void { _path = setValue };
    public function set Id(setValue:int):void { _id = setValue };

    public function PlayListItem(id:int, videoId:int, path:String)
    {
        _videoId = videoId;
        _id = id;
        _path = path;

    }// end function

}

1 个答案:

答案 0 :(得分:1)

我认为您已经使用已注释掉的代码走上正轨。请注意getOperation()将返回AbstractOperation,在我看来它只是指向远程函数的指针。您可以在对象上设置参数,或者在调用send()时简单地传递参数。我知道有些人对参数属性方法有问题,所以简单地在send函数中传递你的参数可能是明智的选择。

以下替换BuildServiceRequestdisplayResult

private function BuildServiceRequest(evt:LoadEvent):void {
    webService.removeEventListener(LoadEvent.LOAD, BuildServiceRequest);
    serviceOperation.addEventListener(ResultEvent.RESULT, displayResult);
    serviceOperation = webService.getOperation("GetPlaylist");
    serviceOperation.send(394575);
}

private function displayResult(e:ResultEvent):void {
    // Store the token as our array.
    _playListItems = e.token;
    var msg:String;

    // Loop through the array
    for each (var entry:Object in _playListItems) {
        msg = "";
        // For every key:value pair, compose a message to trace
        for (var key:String in entry) {
            msg += key + ":" + entry[key] + "   ";
        }
        trace(msg);
    }
}