출처 : http://islet4you.tistory.com/27
포토뷰어라는 예제에 있는 것을 추출해 왔습니다
항상 모듈화라는 숙제를 가지고 보니 이런 좋은 예제가 아닌가 합니다.
package samples.photoviewer
{
import flash.events.*;
import mx.collections.ArrayCollection;
import mx.collections.IViewCursor;
import mx.core.Application;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
import mx.utils.ArrayUtil;
public class PhotoService
{
private var service:HTTPService;
[Bindable]
public var galleries:ArrayCollection;
public function PhotoService(url:String)
{
service = new HTTPService();
service.url = url;
service.addEventListener(ResultEvent.RESULT, resultHandler);
service.send();
} // httpservice를 이용한 호출
private function resultHandler(event:ResultEvent):void
{
var result:ArrayCollection = event.result.galleries.gallery is ArrayCollection
? event.result.galleries.gallery as ArrayCollection
: new ArrayCollection(ArrayUtil.toArray(event.result.galleries.gallery));
var temp:ArrayCollection = new ArrayCollection();
var cursor:IViewCursor = result.createCursor();
while (!cursor.afterLast)
{
temp.addItem(new Gallery(cursor.current));
cursor.moveNext();
}
galleries = temp;
}
}
} // 결과를 arraycollection으로 적용
이 actionscript를 적용해서 구현을 한 예제를 보면
<?xml version="1.0" encoding="utf-8"?>
<!--
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2003-2006 Adobe Macromedia Software LLC and its licensors.
// All Rights Reserved.
// The following is Sample Code and is subject to all restrictions on such code
// as contained in the End User License Agreement accompanying this product.
// If you have received this file from a source other than Adobe,
// then your use, modification, or distribution of it requires
// the prior written permission of Adobe.
//
////////////////////////////////////////////////////////////////////////////////
-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
paddingBottom="0" paddingTop="0"
paddingLeft="0" paddingRight="0"
layout="vertical"
pageTitle="Photo Viewer"
creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.rpc.events.*;
import samples.photoviewer.Gallery;
import samples.photoviewer.PhotoService; //위의 소스를 import
[Bindable]
private var gallery:Gallery;
[Bindable]
private var service:PhotoService;
private function init():void
{
service = new PhotoService("data/galleries.xml"); //httpservice를 호출
}
]]>
</mx:Script>
<mx:Style source="main.css" />
<mx:Binding source="service.galleries.getItemAt(0)" destination="gallery" />
<mx:ViewStack id="views" width="100%" height="100%">
<ThumbnailView id="thumbnailView" gallery="{gallery}"
slideshowView="views.selectedChild = slideshowView"
carouselView="views.selectedChild = carouselView"/>
<CarouselView id="carouselView" gallery="{gallery}"
slideshowView="views.selectedChild = slideshowView"
thumbnailView="views.selectedChild = thumbnailView"/>
<SlideShowView id="slideshowView" gallery="{gallery}"
thumbnailView="views.selectedChild = thumbnailView"
carouselView="views.selectedChild = carouselView"/>
</mx:ViewStack>
</mx:Application>
Viewstack을 가지고 처리를 해주는 것이다.
아울러 여기서 보여주는 콤포넌트에 대해서는 다음시간에 따로 설명을 하도록 하겠습니다.
조금씩 업무별로 가는 프레임웍에 대한 레퍼런스가 만들어지면 올리도록 하겠슴당 ㅋ