Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

MacRoger

Linkar imagem vinda do XML

Recommended Posts

Olá moçada, já procurei a respeito e não conseguir linkar as imagens

 

Fiz este Tutorial ( kirupa Photo Slideshow Using XML and Flash ) e esta funcionando tudo de acordo, porém quero acrescentar um botão (Link) para cada imagem carregada direcionando para o site do anunciante, será que isso é possível? Tendo em vista que se trata de script XML.

 

O Link derevá abrir um POP UP.

 

Olhem aqui a actionscript:

delay = 6000;
//-----------------------
function loadXML(loaded) {
	if (loaded) {
		xmlNode = this.firstChild;
		image = [];
		description = [];
		total = xmlNode.childNodes.length;
		for (i=0; i<total; i++) {
			image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
			description[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
		}
		firstImage();
	} else {
		content = "file not loaded!";
	}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("images.xml");
p = 0;
this.onEnterFrame = function() {
	filesize = picture.getBytesTotal();
	loaded = picture.getBytesLoaded();
	preloader._visible = true;
	if (loaded != filesize) {
		preloader.preload_bar._xscale = 100*loaded/filesize;
	} else {
		preloader._visible = false;
		if (picture._alpha<100) {
			picture._alpha += 15;
		}
	}
};
function nextImage() {
	if (p<(total-1)) {
		p++;
		if (loaded == filesize) {
			picture._alpha = 0;
			picture.loadMovie(image[p], 1);
			desc_txt.text = description[p];
			picture_num();
			slideshow();
		}
	}
}
function prevImage() {
	if (p>0) {
		p--;
		picture._alpha = 0;
		picture.loadMovie(image[p], 1);
		desc_txt.text = description[p];
		picture_num();
	}
}
function firstImage() {
	if (loaded == filesize) {
		picture._alpha = 0;
		picture.loadMovie(image[0], 1);
		desc_txt.text = description[0];
		picture_num();
		slideshow();
	}
}
function picture_num() {
	current_pos = p+1;
	pos_txt.text = current_pos+" / "+total;
}
function slideshow() {
	myInterval = setInterval(pause_slideshow, delay);
	function pause_slideshow() {
		clearInterval(myInterval);
		if (p == (total-1)) {
			p = 0;
			firstImage();
		} else {
			nextImage();
		}
	}
}

Aqui o XML (modificado por mim):

 

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<images>
	<pic>
		<image>fotos1/foto1.jpg</image>
		<caption>black Com.</caption>
	</pic>
	<pic>
		<image>fotos1/foto2.jpg</image>
		<caption>Revista</caption>
	</pic>
	<pic>
		<image>fotos1/foto3.jpg</image>
		<caption>RS Web & Design</caption>
	</pic>
	<pic>
		<image>fotos1/foto4.jpg</image>
		<caption>Anuncie Aqui</caption>
	</pic>
</images>

Fico grato a todos que puderem me ajudar nessa pendenga.

 

Roger.

Compartilhar este post


Link para o post
Compartilhar em outros sites

3 alterações

 

 

para pegar o link que esta no XML, lembre de declarar a variável links como um array

 

 

for (i=0; i<total; i++) {

image = xmlNode.childNodes.childNodes[0].firstChild.nodeValue;

description = xmlNode.childNodes.childNodes[1].firstChild.nodeValue

links = xmlNode.childNodes.childNodes[2].firstChild.nodeValue

 

}

 

 

 

nas funções nextImage() , prevImage() e firstImage(), altere essa linha,

 

picture.loadMovie(image[p], 1);

 

para essas:

 

// cria um movieCLip para carregar a imagem, e adiciona o link a ela
picture.createEmptyMovieClip("img",1)
picture.img.loadMovie(image[p], 1);
picture.link = links[p]
picture.onRelease = function(){
  getURL(this.link)
}

 

e no XMl, você coloca uma TAG a mais em cada <pic>

 

 

 

<pic>
		<image>fotos1/foto1.jpg</image>
		<caption>black Com.</caption>
		<url>www.site.com</url>
</pic>

 

 

isso já deve resolver, vai testando ai que talvez tenha que alterar mais coisa

 

 

 

[]´s

Compartilhar este post


Link para o post
Compartilhar em outros sites

Olá Eder,

Fico grato pela força, aqui no desktop deu certo, vou colocar no servidor para teste.

Te falo o resultado depois.

 

Eu tinha visto este tipo de actionscript em outros mas não saiba onde coloca-lo e qual action teria que substituir.

 

Valew mesmo.

 

Roger.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Prezado Eder,

Consegui abrir em PopUp desta forma:

 

// cria um movieCLip para carregar a imagem, e adiciona o link a ela
picture.createEmptyMovieClip("img",1)
picture.img.loadMovie(image[p], 1);
picture.link = links[p]
picture.onRelease = function(){
  getURL(this.link, "_blank")
}

Porém que não abre a página que esta na Tag do XML:

Esta dando como undefined (e esta vindo o endereço do site e não da Tag na barra de endereço do Internet Explorer)

 

<pic>
		<image>fotos1/foto1.jpg</image>
		<caption>black Com.</caption>
		<url>www.site.com</url>
</pic>

Onde eu estou errando????

 

Grato.

 

Roger.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Aee pessoal...

to com o mesmo problema... fiz umas alterações na AS mas não deu resultado.

 

alguma ajuda ae?

 

valeu.

Compartilhar este post


Link para o post
Compartilhar em outros sites

fiz as 3 alterações q tu falou e realmente aparece a imagem como um link... mas a url q coloco no xml não é carregada....

aparece esse mesmo problema do Roger.

 

Tá funcionando porém com a mensagem (HTTP 404) Não é possível localizar a página da Web

PS: não preciso q seja aberta em pop-up... só q o link da imagem funcione.

 

Obrigado.

Compartilhar este post


Link para o post
Compartilhar em outros sites

consegui alguma coisa, mas ta com falha ainda...

Criei um botão (instanciado como botao_link_imagem) e coloquei a ação abaixo no flash.

 

botao_link_imagem.onPress = function() {
   getURL(xmlNode.childNodes[p].childNodes[2].firstChild.nodeValue, "_blank");
};

no XML acrescentei as tags <link></link>:

 

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<images>
	<pic>
		<image>imagemA1_large.jpg</image>
		<caption>imagem de teste A1</caption>
		<thumbnail>imagemA1_miniatura.jpg</thumbnail>
		<link>http://www.imasters.com.br</link>
	</pic>
</images>

O PROBLEMA é que quando clico no botão ele abre o <thumbnail>imagemA1_thumb.jpg</thumbnail> no navegador e não o link.

Se eu mudar a ordem das tags para image, caption, link e thumbnail funciona o link e o botão direciona para o site, MAS ae ele desativa as últimas tags (thumbnail) e a galeria fica sem as imagens miniatura.... Resumindo, o flash só consegue puxar as informações até a 3ª tag.

 

talvez tenha q adicionar alguma coisa na ação abaixo (que está na AS do Flash) referente à tag LINK... tipo link= []; e link = xmlNode.childNodes.childNodes[2].firstChild.nodeValue;... tentei isso, mas não consegui, talvez pq tenha colocado errado.

 

segue a AS do flash completa:

function loadXML(loaded) {
	if (loaded) {
		xmlNode = this.firstChild;
		image = [];
		description = [];
		thumbnails = [];
		total = xmlNode.childNodes.length;
		for (i=0; i<total; i++) {
			image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
			description[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
			thumbnails[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
			thumbnails_fn(i);
		}
		firstImage();
	} else {
		content = "file not loaded!";
	}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("images.xml");
///////////////////////////////////// 
listen = new Object();
listen.onKeyDown = function() {
	if (Key.getCode() == Key.LEFT) {
		prevImage();
	} else if (Key.getCode() == Key.RIGHT) {
		nextImage();
	}
};
Key.addListener(listen);
previous_btn.onRelease = function() {
	prevImage();
};
next_btn.onRelease = function() {
	nextImage();
};
///////////////////////////////////// 
p = 0;
this.onEnterFrame = function() {
	filesize = picture.getBytesTotal();
	loaded = picture.getBytesLoaded();
	preloader._visible = true;
	if (loaded != filesize) {
		preloader.preload_bar._xscale = 100*loaded/filesize;
	} else {
		preloader._visible = false;
		if (picture._alpha<100) {
			picture._alpha += 10;
		}
	}
};
function nextImage() {
	if (p<(total-1)) {
		p++;
		if (loaded == filesize) {
			picture._alpha = 0;
			picture.loadMovie(image[p], 1);
			desc_txt.text = description[p];
			picture_num();
		}
	}
}
function prevImage() {
	if (p>0) {
		p--;
		picture._alpha = 0;
		picture.loadMovie(image[p], 1);
		desc_txt.text = description[p];
		picture_num();
	}
}
function firstImage() {
	if (loaded == filesize) {
		picture._alpha = 0;
		picture.loadMovie(image[0], 1);
		desc_txt.text = description[0];
		picture_num();
	}
}
function picture_num() {
	current_pos = p+1;
	pos_txt.text = current_pos+" / "+total;
}
function thumbNailScroller() {
	// thumbnail code! 
	this.createEmptyMovieClip("tscroller", 1000);
	scroll_speed = 10;
	tscroller.onEnterFrame = function() {
		if ((_root._ymouse>=thumbnail_mc._y) && (_root._ymouse<=thumbnail_mc._y+thumbnail_mc._height)) {
			if ((_root._xmouse>=(hit_right._x-40)) && (thumbnail_mc.hitTest(hit_right))) {
				thumbnail_mc._x -= scroll_speed;
			} else if ((_root._xmouse<=(hit_left._x+40)) && (thumbnail_mc.hitTest(hit_left))) {
				thumbnail_mc._x += scroll_speed;
			}
		} else {
			delete tscroller.onEnterFrame;
		}
	};
}
function thumbnails_fn(k) {
	thumbnail_mc.createEmptyMovieClip("t"+k, thumbnail_mc.getNextHighestDepth());
	tlistener = new Object();
	tlistener.onLoadInit = function(target_mc) {
		target_mc._x = hit_left._x+(target_mc._width+5)*k;
		target_mc.pictureValue = k;
		target_mc.onRelease = function() {
			p = this.pictureValue-1;
			nextImage();
		};
		target_mc.onRollOver = function() {
			this._alpha = 50;
			thumbNailScroller();
		};
		target_mc.onRollOut = function() {
			this._alpha = 100;
		};
	};
	image_mcl = new MovieClipLoader();
	image_mcl.addListener(tlistener);
	image_mcl.loadClip(thumbnails[k], "thumbnail_mc.t"+k);
}


bt.onPress = function() {
   getURL(xmlNode.childNodes[p].childNodes[2].firstChild.nodeValue, "_blank");
};

 

Valeu

Compartilhar este post


Link para o post
Compartilhar em outros sites

testa adicionar mais um childNodes:

 

 

getURL(xmlNode.childNodes[p].childNodes[2].firstChild.nodeValue.childNodes, "_blank");

 

 

ou

 

 

getURL(xmlNode.childNodes[p].childNodes[2].firstChild.childNodes.childNodes, "_blank");

 

vai testando ai para ver qual funciona

 

 

[]´s

Compartilhar este post


Link para o post
Compartilhar em outros sites

ok, vi que você guardou o endereço nessa variável "thumbnails", entao você pode usa-la para acessar:

 

 

bt.onPress = function() {
   getURL(thumbnails[0])
}

 

mas veja se você declarou essa variável como Array no inicio do código

 

 

 

[]´s

Compartilhar este post


Link para o post
Compartilhar em outros sites

Deu certo, mas com uma falha (o link abre 2 vezes... em abas diferentes no navegador, como se eu clicasse 2x)

 

o endereço do site estava na variável "link"... na variável "thumbnails" estava o endereço da imagem thumb.

coloquei essa variáveis no início do código, como array:

 

links = [];
links[i] = xmlNode.childNodes[i].childNodes[3].firstChild.nodeValue;
ae depois coloquei a ação do botão mas corrigi o valor "3" no childNodes:

 

bt.onPress = function() {
	getURL(xmlNode.childNodes[p].childNodes[3].firstChild.nodeValue, "_blank");
};
assim funcionou certo, mas so com o problema de o mesmo endereço abrir 2x no navegador.

o XML continua o msm:

 

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<images>
	<pic>
		<image>kresge.jpg</image>
		<caption>Kresge</caption>
	<thumbnail>kresge_sm.jpg</thumbnail>
	<link>http://www.imasters.com.br</link>
	</pic>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.