By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,069 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

listener run my function 2 times

P: 2
Hello, I hope I could get some help with this issue, since I give up. It is too much for just me.
This script is originally from MX. I have a hard time trying to translate to AS3.
Anyway. There were a moment when I have to mix the original code with the slide show tutorial from kirupa site. Right now is almost functional. But it behave very weird when is online.
My problem is this. After all the work my final touch is to place a preloader to each loaded image(I already made it). But the secuence should be IF LOADED...then execute the FX and summ 1 number to the secuence...
At the end everything works OK, locally, but online the process show the previous images before it get to the preloader secuence of the new comming image. Becouse of this I step a few test behind the actual and noted this:
When the user see the first set of images, everything is OK, but if he move to other, then the listener seem to execute the click function 2 times, becouse the trace window show 2 outputs. At the end we have the right number, but I don't know if this is the problem.

This is the code:
[HTML]import flash.filters.BlurFilter;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.controls.ComboBox;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import fl.data.DataProvider;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.*;
import flash.net.URLRequest;
import fl.transitions.*;


var movider:Number = 35;
var moviizq:Number = -45;
var filename:String = "modelo03.xml";
//var filename:String = "http://quatpanama.com/qproyectos/convertidor05_fra.php";
var foundAlbum:Number;
var numPhotosOnPage:Number;


var xmlLoader:URLLoader = new URLLoader();
var album:XML = new XML();
var fileName:String;
xmlLoader.addEventListener(Event.COMPLETE, envio);
xmlLoader.load(new URLRequest(filename));


function envio(e:Event):void {
XML.ignoreWhitespace = true;
var album:XML = new XML(e.target.data);
newAlbum(album);
}

function newAlbum(album_item:XML):void {
for (var e:int=0; e<album_item.length(); e++) {
if (album_item[e].name().localName == "albums") {
var albumsDescryption:XML = new XML();
albumsDescryption = album_item[e];
}
}
buildAlbumList(albumsDescryption);
}
var albumCount = 0;

function buildAlbumList(albumsDescryption:XML):void {
var albdesc_pars:XMLList = albumsDescryption.photoset;
//trace(albdesc_pars.length());
for (var u:int=0; u<albdesc_pars.length(); u++) {
var albumes_long:Number = albdesc_pars.length();
var album_element:XML = albdesc_pars[u];
if (album_element.name() == "photoset") {
var etiqueta:String = album_element.attribute("name");
var datos:String = album_element.attribute("name");
combo(etiqueta, datos);
}
}
if (albumCount>0) {
chooseAlbum.selectedIndex = 0;
var currentAlbum = chooseAlbum.selectedItem.data;
//trace("cierto");
//trace(albumDesc);
cambiador();
}
function cambiador() {
var currentAlbum = chooseAlbum.selectedItem.data;
var showPhoto = 0;
var isNewAlbum = 1;
var albumselect = chooseAlbum.selectedIndex;
album_label.text = albdesc_pars[albumselect].attribute("album_desc");
findAlbums(albumsDescryption, currentAlbum, showPhoto,isNewAlbum);
}

////////////FUNCIONS del COMBObox //////////////////////////////////////////////////////////////////////////
//funcion de llenado
function combo() {
albumCount++;
chooseAlbum.addItem( { label: etiqueta, data: datos } );
chooseAlbum.addEventListener(Event.CHANGE, changeAlbum);
}
//FUNCION DEL CLICK
function changeAlbum (event:Event):void{
var currentAlbum = chooseAlbum.selectedItem.data;
//trace(currentAlbum);
var showPhoto = 0;
var isNewAlbum = 1;
var albumselect = chooseAlbum.selectedIndex;
//trace(albumselect);
//album_label.text = "wewewe";
//album_label.text = albdesc_pars[albumselect].toString();
album_label.text = albdesc_pars[albumselect].attribute("album_desc");
//trace(albdesc_pars[albumselect].attribute("album_desc"));
findAlbums(albumsDescryption, currentAlbum, showPhoto,isNewAlbum);
}

// FIN DEL COMBOBOX ///////////////////////////////////////////////////////////////////////////////////////////
function findAlbums(albumsDescryption, currentAlbum, showPhoto,isNewAlbum) {
//trace(albumsDescryption.children().length());
for (var ui=0; ui<albumsDescryption.children().length(); ui++) {
//trace ("looking for match: currentAlbum "+currentAlbum + " to " + albumsDescryption.children()[ui].attribute("name").toLowerCase());

if (albumsDescryption.children()[ui].attribute("name").toLowerCase() == currentAlbum.toLowerCase()) {
//trace("true");
foundAlbum = 1;
//trace ("-------------");
//find out where the images will be
//imgBase = albumsDescryption.childNodes[count02].attributes.imagebase;
//trace ("imagebase is "+imgBase);
var photoPage = albumsDescryption.children()[ui];
var numPhotos = photoPage.children().length();
break;
}
}
//trace(photoPage);
displayPhoto(photoPage, numPhotos)
}


function displayPhoto(photoPage, numPhotos) {
var fotonu = photoPage.children().children().attribute("src").l ength();
var titulo:XMLList = photoPage.children().children().attribute("title") ;
var fuente:XMLList = photoPage.children().children().attribute("src");
var desc:XMLList = photoPage.children().children().attribute("caption ");
/*for (var a:int=0; a<titulo.length(); a++){
//trace ("ITEM "+a+"==> "+titulo[a]);
}
for (var e:int=0; e<fuente.length(); e++){
var imagesourcefile:String = fuente[e];
//trace ("ITEM "+e+"==> "+fuente[e]);
}
for (var i:int=0; i<desc.length(); i++){
//trace ("ITEM "+i+"==> "+desc[i]);
}*/


fwdButton.addEventListener(MouseEvent.CLICK, nextImage);
bkButton.addEventListener(MouseEvent.CLICK, prevImage);
var p = 0;
firstImage();

function firstImage() {
var albumHolder:Loader = new Loader();
var url:String = "quat_admin/images/gallery/"+fuente[0]
var urlReq:URLRequest = new URLRequest(url);
albumHolder.load(urlReq);
conte.addChild(albumHolder);
des.photoCaptionInfo.text = desc[0];
photoTitleInfo.text = titulo[0];
var sentido = 30;
filtros(sentido);
picture_num();
}
var myInterval;
function nextImage(event:MouseEvent){
trace("FUNCTION START---> p: "+p);
conte.x = -52
var fotonu = photoPage.children().children().attribute("src").l ength();
p++
p %= fotonu;
var albumHolder:Loader = new Loader();
var url:String = "quat_admin/images/gallery/"+fuente[p]
var urlReq:URLRequest = new URLRequest(url);
albumHolder.load(urlReq);
conte.addChild(albumHolder);
des.photoCaptionInfo.text = desc[p];
photoTitleInfo.text = titulo[p];
var sentido = 30;
trace("END OF FUNCTION-----------------> P: "+p);
filtros(sentido);
picture_num();
clearInterval(myInterval);
}

function prevImage(event:MouseEvent){
conte.x = -52
var fotonu = photoPage.children().children().attribute("src").l ength();
clearInterval(myInterval);
if (p>0) {
p--;
} else {
p = fotonu-1;
}
var albumHolder:Loader = new Loader();
var url:String = "quat_admin/images/gallery/"+fuente[p]
var urlReq:URLRequest = new URLRequest(url);
albumHolder.load(urlReq);
conte.addChild(albumHolder);
des.photoCaptionInfo.text = desc[p];
photoTitleInfo.text = titulo[p];
var sentido = -131;
filtros(sentido);
picture_num();

}



function picture_num() {
var fotonu = photoPage.children().children().attribute("src").l ength();
var current_pos = p+1;
//trace("foto cant: "+ fotonu+"fotos actual: "+current_pos+" la P:"+p);
pos_txt.text = current_pos+" / "+fotonu;
}

function filtros (sentido){

var myTween:Tween = new Tween(conte, "blur", Elastic.easeInOut, 20, 0, 20, false);
myTween.addEventListener(TweenEvent.MOTION_CHANGE, handleReset);
function handleReset(e:TweenEvent):void {
conte.filters = [new BlurFilter(conte.blur, conte.blur, 1)];
}
var xPosT:Tween = new Tween(conte, "x", Regular.easeInOut, -52, sentido, 3, true);
xPosT.addEventListener(TweenEvent.MOTION_CHANGE, marcador);
function marcador(e:TweenEvent):void {
var val = Math.round(conte.x);
pos.text = val;
}

}
}




}[/HTML]
Sep 9 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.