Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Flash: XML Image Rotator via Buttons
Old 04-08-2011, 08:30 AM Flash: XML Image Rotator via Buttons
Burnsie's Avatar
Skilled Talker

Posts: 81
Trades: 0
Hi All
I have been away from Flash for a while so please be gentle with me!
I have a scipt that I found from a tutorial somewhere that allows me to cycle through a group of images held in an XML file, via 'previous' and 'next' buttons. The images then fade and blur into the next or previous image in the xml file, which is the effect I am looking for. However, what I would like to do is have a seperate button for each image. So button 'a' loads picture 'a' and button 'b' loads picture 'b' and so on. So the images don't have to load sequentialy but in what ever order the buttons are clicked but with the same blurring effect. I hope this makes sense!

Here is my code:

import flash.filters.BlurFilter;
stop();
counter=-1;
//Check if the GET parameter XMLfile is set, if not use a default file
if(_root.XMLfile==undefined || _root.XMLfile==""){
_root.XMLfile="myimagerotator.xml";
}
//Fix the size of the content
Stage.scaleMode = "noScale";
//There are 2 movie clips used, and they are rotated
currentTop=0;
//Get the percentage loaded of the next image
function getPercentLoaded(){
return(100*eval("displayImage"+currentTop).getByte sLoaded()/eval("displayImage"+currentTop).getBytesTotal());
}
//Set the current image to the next image
function nextListImage(){
currentImage=(currentImage+1)%imageList.length;
return currentImage;
}
//Set the current image to the previous image
function previousListImage(){
currentImage=(currentImage-1)%imageList.length;
if(currentImage<0){currentImage=imageList.length-1;}
return currentImage;
}
//Reset the delay counter, swap the images in depth, and make the top invisible
function nextImage(){
counter=200;
currentTop=(currentTop+1)%2;
eval("displayImage"+currentTop).swapDepths(eval("d isplayImage"+((currentTop+1)%2)));
eval("displayImage"+currentTop)._alpha=0;
return currentTop;
}
//Scale the image to fit the window
function fitImages(){
stageRatio=Stage.width/Stage.height;
docprops=stageRatio+" "+Stage.width+" "+Stage.height;
topImageRatio=eval("displayImage"+currentTop)._wid th/eval("displayImage"+currentTop)._height;
if(isNaN(topImageRatio) || topImageRatio==Infinity){
}else if(topImageRatio<stageRatio){
if(eval("displayImage"+currentTop)._height!=Stage. height){
eval("displayImage"+currentTop)._width*=Stage.heig ht/eval("displayImage"+currentTop)._height;
eval("displayImage"+currentTop)._height=Stage.heig ht;
}
}else{
if(eval("displayImage"+currentTop)._width!=Stage.w idth){
eval("displayImage"+currentTop)._height*=Stage.wid th/eval("displayImage"+currentTop)._width;
eval("displayImage"+currentTop)._width=Stage.width ;
}
}
eval("displayImage"+currentTop)._x=(550-eval("displayImage"+currentTop)._width)/2;
eval("displayImage"+currentTop)._y=(400-eval("displayImage"+currentTop)._height)/2;
}
var imageList:Array = Array();
var myXml:XML = new XML();
myXml.ignoreWhite = true;
myXml.load(_root.XMLfile);
//Load the xml file and parse it
myXml.onLoad = function() {
currentImage=myXml.childNodes[0].childNodes.length-1;
for(imageIndex=0;imageIndex<myXml.childNodes[0].childNodes.length;imageIndex++){
imageList[imageIndex]=myXml.childNodes[0].childNodes[imageIndex].childNodes[0].childNodes[0];
}
//reset the delay counter
counter=200;
//load an image
loadMovie(imageList[nextListImage()], eval("displayImage"+nextImage()));
}
onEnterFrame=function(){
counter--;
//if the xml file has loaded
if(imageList.length>0 && counter>(-1)){
//if the delay counter hits 0, load the next image
if(counter==0){
loadMovie(imageList[nextListImage()], eval("displayImage"+nextImage()));
}
//start the transition after the next image has loaded
if(eval("displayImage"+currentTop)._alpha<100 && eval("displayImage"+currentTop).getBytesLoaded()== eval("displayImage"+currentTop).getBytesTotal() && eval("displayImage"+currentTop).getBytesLoaded()>0 ){
//scale the new image
fitImages();
//quality of the blur
quality = 2;
//The next 4 lines apply a blur to the transition. Remve these lines if the applet runs slow
var filter:BlurFilter = new BlurFilter(eval("displayImage"+((currentTop+1)%2)) ._alpha, eval("displayImage"+((currentTop+1)%2))._alpha, quality);
eval("displayImage"+currentTop).filters=[filter];
var filter2:BlurFilter = new BlurFilter(eval("displayImage"+currentTop)._alpha, eval("displayImage"+currentTop)._alpha, quality);
eval("displayImage"+((currentTop+1)%2)).filters=[filter2];

//fade one in and one out
eval("displayImage"+currentTop)._alpha+=4;
eval("displayImage"+((currentTop+1)%2))._alpha-=4;
//image is still loading
}else if(eval("displayImage"+currentTop).getBytesLoaded( )!=eval("displayImage"+currentTop).getBytesTotal() ){
counter=200;
}
}
}


This is the code on my previous button:

on(press){
loadMovie(_level0.imageList[_level0.previousListImage()], eval("_level0.displayImage"+_level0.nextImage()));
playpause.gotoAndStop(1);
}

And on my next button:

on(press){
loadMovie(_level0.imageList[_level0.nextListImage()], eval("_level0.displayImage"+_level0.nextImage()));
playpause.gotoAndStop(1);
}


My xml file is just a list of images.

How do I make my buttons point to specific images and not just 'previous' and 'next'? If there is another way to do this then that is fine.

Cheers in advance

Burnsie
Burnsie is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-09-2011, 10:36 AM Re: Flash: XML Image Rotator via Buttons
OleTom's Avatar
Extreme Talker

Posts: 176
Location: Out there some where
Trades: 0
I have been using Swish a very inexpensive flash program that makes this very easy check out my rotator links on a site I just finished

http://constructionworkers.info/jobsite/ it only took me a few minutes to make that menu google Swish the mini max 3 can do that with images buttons what ever

PS: The menu in the middle of the page not at top
__________________
Life is Good,OleTom

Please login or register to view this content. Registration is FREE

Last edited by OleTom; 10-09-2011 at 10:38 AM..
OleTom is offline
Reply With Quote
View Public Profile Visit OleTom's homepage!
 
Reply     « Reply to Flash: XML Image Rotator via Buttons
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20893 seconds with 12 queries