3/16/2010 12:52:10 AM
Title:
slideshow
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
<mx:Style source="assets/style.css" />
<mx:XML id="imageXML" source="assets/imagegallary.xml" />
<mx:Script>
<![CDATA[
import flash.external.*;
import flash.events.TimerEvent;
import flash.utils.Timer;
import mx.controls.Alert;
import view.pageCanvas;
import view.buttonForm;
public var xmlData : XML;
public var minuteTimer:Timer;
public var count : int = 0;
public var imgCount : int = 0;
public var clkImg : Number = 0;
public var pagecanvas : pageCanvas;
private var clk : Number = 0;
public var button : buttonForm = new buttonForm();
private function init() : void
{
ShortTimer();
/* if (ExternalInterface.available)
ExternalInterface.addCallback("sendDataToFlex", receiveData); */
}
public function ShortTimer() : void
{
xmlData = new XML(imageXML);
count = xmlData.children().length();
pagination.removeAllChildren();
for(var i : Number=0;i<count;i++)
{
pagecanvas = new pageCanvas();
pagination.addChild(pagecanvas);
pagecanvas.page.id =String(i);
trace(pagecanvas.page.id );
pagecanvas.page.addEventListener(MouseEvent.CLICK,viewImg);
pagecanvas.pageNum.text = String(i+1);
}
// creates a new five-second Timer
minuteTimer = new Timer(3000,count);
clk = 0;
// designates listeners for the interval and completion events
minuteTimer.addEventListener(TimerEvent.TIMER, onTick);
minuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
// starts the timer ticking
minuteTimer.start();
}
public function viewImg(evt : MouseEvent) : void
{
xmlData = new XML(imageXML);
var num : String = evt.currentTarget.id;
trace(evt.currentTarget);
var i : int = new int( evt.currentTarget.id);
trace("page num " + i);clk = i;
txt.text = xmlData.imageDetails[i].notes;
img.source = xmlData.imageDetails[i].pathName;
minuteTimer.delay;
//set all counter values initials
initCount();
imgCount = clk;
//enable next & prev button
prevBtn_enable();
nextBtn_enable();
}
private function initCount() : void
{
count = xmlData.children().length();
count = (count-clk);
}
public function onTick(event:TimerEvent):void
{
// count the XML data
xmlData = new XML(imageXML);
if(clk == 0)
{
imgCount = event.target.currentCount-1;
// display the XML data in text box and image box
txt.text = xmlData.imageDetails[imgCount].notes;
img.source = xmlData.imageDetails[imgCount].pathName;
}
else if(clk!=0 && clk < xmlData.children().length() )
{
trace("count "+ count);
imgCount = clk;
txt.text = xmlData.imageDetails[clk].notes;
img.source = xmlData.imageDetails[clk].pathName;
clk++;
}
}
public function onTimerComplete(event:TimerEvent):void
{
//start the counter again for contineous image display
ShortTimer();
}
private function prevImg() : void
{
//minuteTimer.stop();
imgCount = imgCount-1;
clk = imgCount;
initCount();
txt.text = xmlData.imageDetails[imgCount].notes;
img.source = xmlData.imageDetails[imgCount].pathName;
prevBtn_enable();
nextBtn_enable();
}
private function nextImg() : void
{
//minuteTimer.stop();
imgCount = imgCount+1;
clk = imgCount;
initCount();
txt.text = xmlData.imageDetails[imgCount].notes;
img.source = xmlData.imageDetails[imgCount].pathName;
prevBtn_enable();
nextBtn_enable();
}
private function prevBtn_enable() : void
{
if(imgCount > 0)
prvsBtn.enabled = true;
else
{
prvsBtn.enabled = false;
}
}
private function nextBtn_enable() : void
{
if(imgCount < count-1)
nextBtn.enabled = true;
else
nextBtn.enabled = false;
}
private function clickEvent() : void
{
if(btn.label == "pause")
{
btn.label = "play";
minuteTimer.stop();
}
else if(btn.label == "play")
{
btn.label = "pause";
minuteTimer.start();
}
}
private function imageClick() : void
{
var path : String = img.source.toString();
//var path : String = xmlData.imageDetails[imgCount].pathName;
ExternalInterface.call("callScript",path,imgCount);
}
</mx:Script>
<mx:Canvas styleName="CanvasStyle" x="387" y="203" width="416" height="322" horizontalScrollPolicy="off" verticalScrollPolicy="off" backgroundColor="black" >
<mx:Image id="img" click="imageClick()" maintainAspectRatio="false" completeEffect="Dissolve" width="402" height="303" x="6" y="7"/>
<mx:Button id="prvsBtn" click="prevImg()" label="P" y="291" x="129" width="34" height="19"/>
<mx:HBox id="pagination" x="176" y="290" horizontalAlign="right" />
<mx:Button id="nextBtn" click="nextImg()" label="N" width="34" height="19" y="290" x="314"/>
<mx:Button id="btn" y="288" x="352" label="pause" click="clickEvent()"/>
<mx:Text id="txt" y="291" x="10" textAlign="right" />
</mx:Canvas>
</mx:Canvas>
question : here i added a pagecanvas dinamically and give them ids.Then when i click the image, corresponding to that canvas should be activate with a style. how could icall the ids of the pagecanvas during runtime.
3/16/2010 2:36:28 AM
you can declare an array out side function. And store the refrence of the pageCanvas in that array
//declare array outside the function
private arrayCanvas:Array= new Array();
// store the refrence of the page canvas just after you set the id
pagecanvas.page.id =String(i);
arrayCanvas[i]=String(i);
now you can access you page canvas later from arrayCanvas
3/16/2010 3:03:07 AM
Thanks for your reply. i will try on that.
one more doubt related to that code.
Question : I added those pagecanvas in a Hbox. When i call the pagecanvas id with the Hbox id(eg: Hboxid.pagecanvasid.style=something), it show an error message "undefined name or property". how call those pagecanvas without any eventhandling procedure.
3/16/2010 4:25:19 AM
to change a style on runtime using actionscript you must use following syntax:
// example using setstyle to change or set paddingTop style
pagecanvasid.setStyle("paddingTop", 12);