2015-01-13 1 views
0

객체를 읽고 배열로 저장해야합니다. 나는 C#에서 그런 일을했지만 actionscript에서 어떻게하는지 알 수 없다.webservice 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에서 간단한 결과를 얻는 방법을 알고 있지만, parameteres와 객체를 취득하고 저장하는 방법을 모르겠어요.

서비스에는 개체 배열 (id, videoId, path)을 반환하는 GetPlaylist (int value) 메서드가 있습니다. 어떻게 처리하고 저장합니까?

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

나는 당신이 주석 처리 된 코드로 올바른 길을 가고 있다고 생각합니다. getOperation()AbstractOperation을 반환 할 것이라는 점에 유의하십시오. 내 마음에 단순히 리모컨 기능에 대한 포인터입니다. send()에 전화 할 때 개체에 인수를 설정하거나 단순히 인수를 전달할 수 있습니다. 어떤 사람들은 인수 프로퍼티 접근법에 문제가 있다는 것을 알고 있으므로 단순히 send 함수에서 인수를 전달하는 것이 현명한 방법 일 수 있습니다.

의 I는 그것을 알아 냈 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); 
    } 
} 
+0

교체 다음과 같습니다. 조금 달라 졌다고 생각합니다. 여기 어떻게 : asynctoken 및 응답자를 사용하십시오. 진정한 응답자로부터 나는 물건을 읽고 내가 필요한 곳에 보관하고 있습니다. 여기에 매우 제한된 단어 수 : ( ) 토큰 = serviceOperation.send (videoIdFrom); \t \t \t token.addResponder (새 Responder (getNewPlaylist, faultError)); – CikLinas