그림을 자세히 보시려면 그림을 클릭하세요.문서에 첨부된 이미지는 축소하여 올렸습니다. 그림을 자세히 보시려면 그림 파일을 클릭하세요. 큰 화면으로 보실 수 있습니다. ^^

Embed 명령을 이용하여 이미지를 내장하고 타이머 이벤트와 랜덤 함수를 이용하여Image 컴포넌트에 이미지를 임의로 표시한다.

소스 및 폼

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="init()">

<mx:Script>
<![CDATA[

import mx.controls.Image;

private const TIMER_INTERVAL:int = 200; // m sec 단위

private var tmTimer : Timer;
private var randomData : int;

[Bindable] [Embed(source='image/black.png')] private var imgBlack:Class;
[Bindable] [Embed(source='image/red.png')] private var imgRed:Class;
[Bindable] [Embed(source='image/blue.png')] private var imgBlue:Class;
[Bindable] [Embed(source='image/green.png')] private var imgGreen:Class;
[Bindable] [Embed(source='image/white.png')] private var imgWhite:Class;

private function init():void {
tmTimer = new Timer( TIMER_INTERVAL );
tmTimer.addEventListener(TimerEvent.TIMER, updateTimer);

tmTimer.start();
}

private function updateTimer(evt:TimerEvent):void {

randomData = Math.round(Math.random() * 4 );

switch(randomData)
{
case 0 : imgTarget.source = imgBlack; break;
case 1 : imgTarget.source = imgRed; break;
case 2 : imgTarget.source = imgBlue; break;
case 3 : imgTarget.source = imgGreen; break;
case 4 : imgTarget.source = imgWhite; break;
}

}

]]>
</mx:Script>

<mx:Image x="178" y="140" width="64" height="64" source="{imgBlack}" id="imgTarget"/>

</mx:Application>

실행 화면 캡쳐

 

예제 실행