从 webservice 动作脚本中读取对象

Reading objects from webservice actionscript

我需要读取对象并将它们保存在数组中。我是在 C# 上做的,但不知道如何在 actionscript 上做。

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 获得简单的结果,但不知道如何获得带有参数的对象并保存它们。

服务有一个方法 GetPlaylist(int value),其中 returns 一个对象数组(id、videoId、路径)。如何处理并保存它们?

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

}

我认为您的注释掉的代码是正确的。请注意 getOperation() will return an AbstractOperation, which in my mind is simply a pointer to the remote function. You can set arguments on the object, or simply pass the arguments when you call 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);
    }
}