10/18/2010 4:30:13 AM
Title:
effects
I have done with image gallery as below
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%">
<mx:Script>
<![CDATA[
[Bindable]
private var imageindex:int = 0;
private function changeImage(value:String):void {
switch(value) {
case "previous" :
img1.visible = false;
imageindex--;
break;
case "next" :
img1.visible = false;
imageindex++;
break;
}
img1.visible = true;
}
]]>
</mx:Script>
<mx:XML id="xmlImageData" source="gallery.xml"/>
<mx:XMLListCollection id="xmlcollection" source="{xmlImageData.image}"/>
<mx:HBox width="100%" height="100%" paddingBottom="20" paddingLeft="20" paddingRight="20" paddingTop="20">
<mx:Canvas width="100%" height="100%" id="canvas1">
<mx:Image id="img1" width="100%" height="100%" maintainAspectRatio="true" verticalAlign="middle" horizontalAlign="center" source="{xmlcollection.getItemAt(imageindex)}" scaleContent="true">
</mx:Image>
<mx:VBox width="100%" height="100%" horizontalAlign="center">
<mx:Spacer height="100%" width="100%"/>
<mx:HBox width="100%" height="100%" verticalAlign="bottom" horizontalAlign="center">
<mx:Button label="Previous" click="changeImage('previous')" width="100" enabled="{imageindex!=0}"/>
<mx:Button label="Next" click="changeImage('next')" width="100" enabled="{imageindex!=xmlcollection.length-1}"/>
</mx:HBox>
</mx:VBox>
</mx:Canvas>
</mx:HBox>
</mx:Application>
And the xml is as below
<galleryImages>
<image>images/12.jpg</image>
<image>images/amazing-photo-flowers-dew-purple-orchid-stunning.jpg</image>
<image>images/Conservatory-of-Flowers-Orchid-Screensaver.jpg</image>
<image>images/cut-flowers.JPG</image>
<image>images/orange_flower.jpg</image>
<image>images/pink-white-flowers-screensaver.jpg</image>
<image>images/flowers_4.jpg</image>
<image>images/two_flowers.preview.jpg</image>
</galleryImages>
My requirement is when I click on next/previous button every image comes with different effect
for example first image open with zoom effect,second resize
So please provide me the solution How I do this?(with code)
Davis
Points: 780
Posts:0
10/18/2010 5:20:05 AM
first of all declare different effects in mxml that you want to use like this , I have declared 2 only
<mx:Zoom id="myZoomShow" zoomHeightFrom="0.0" zoomWidthFrom="0.0" zoomHeightTo="1.0" zoomWidthTo="1.0"/>
<mx:Rotate id="myRotateShow"/>
// add default showEffect on image component
showEffect="{myZoomShow}"
//in your changeImage function do something like this
private function changeImage(value:String):void {
switch(value) {
case "previous" :
img1.visible = false;
imageindex--;
break;
case "next" :
img1.visible = false;
imageindex++;
break;
}
// below condition will check the old effect and change to new one before showing image
if (img1.showEffect == myZoomShow){
img1.showEffect= myRotateShow;
}else if (img1.showEffect == myRotateShow){
// someOthereffect will be id of your third effect that i didn't declare
img1.showEffect= someOthereffect;
}else if (img1.showEffect == someOthereffect){
img1.showEffect= myZoomShow;
}
img1.visible = true;
}
10/18/2010 5:51:18 AM
Hi Davis,
img1.ShowEffect is not shown in my IDE.
Thanks for ur reply but this solution is not working.If possible provide me another solution.
Davis
Points: 780
Posts:0
10/18/2010 7:30:32 AM
Actuali I gave you the concept , I was not on my development PC so was typing actionscript in browser only. To set a style through actionscript you need to set it using setStyle and you can read the previous set style using getStyle
like this
//to set the showeffect use following syntax in actionscript
img1.setStyle("showEffect", myZoomShow);
//instead of
img1.showEffect= myZoomShow;
//In conditions use the syntax to read the already set showEffect
if(img1.getStyle("showEffect") == myZoomShow){
//instead of
if (img1.showEffect == myZoomShow){
10/18/2010 10:24:42 PM
Hi Davis,
Thanks for the solution It's working fine.
Thanks.