<?xml version="1.0" ?>
<noticias>
<noticia titulo="titulo noticia 1"><![CDATA[---- Contudo da noticia 1 ----]]></noticia>
<noticia titulo="titulo noticia 2"><![CDATA[---- Contudo da noticia 2 ----]]></noticia>
...
<noticia titulo="titulo noticia N"><![CDATA[---- Contudo da noticia N ----]]></noticia>
</noticias>
// configurando o objeto notícias
// cria o objeto XML que vai carregar o arquivo noticias.xml
var noticias:XML = new XML();
// dizemos para o objeto notícias ignorar os espaços em branco entre as tags
noticias.ignoreWhite = true;
// definimos o evento que será disparado quando o objeto "noticias" terminar de carregar as notícias
noticias.onLoad = function(sucesso:Boolean) {
// se "sucesso" for verdadeiro significa que o arquivo foi carregado e podemos mostrar o conteúdo dele
if (sucesso) {
listarNoticias();
} else {
// avisa que ocorreu algum erro durante o carregamento
trace("erro ao carregar o arquivo noticias.xml");
}
};
//
// criamos os TextFields para exibir as informações
_root.createTextField("tfLista", _root.getNextHighestDepth(), 5, 5, 120, 390);
_root.createTextField("tfConteudo", _root.getNextHighestDepth(), 130, 5, 360, 390);
// formatamos os TextFields
_root.tfLista.border = true
_root.tfLista.background = true;
_root.tfLista.color = 0x000000
_root.tfLista.html = true
_root.tfLista.multiline = true
_root.tfLista.selectable = false
//
_root.tfConteudo.border = true
_root.tfConteudo.background = true;
_root.tfConteudo.color = 0x000000
_root.tfConteudo.html = true
_root.tfConteudo.multiline = true
_root.tfConteudo.wordWrap = true
_root.tfConteudo.selectable = true
//
// FUNÇÕES
// função para mostra a lista de notícias carregadas
function listarNoticias():Void {
// variáveis temporárias
var i:Number = 0;
var titulo:String;
var totalNoticias:Number = noticias.firstChild.childNodes.length;
// definimos como "" o "tfLista" para tirar algum texto que não deva estar ali
_root.tfLista.htmlText = "";
// aqui nos fazemos um loop para colocar os títulos de cada notícia no "tfLista" e definimos o link
while (i<totalNoticias) {
// achamos o titulo na notícia "i"
titulo = noticias.firstChild.childNodes.attributes.titulo;
// inserimos no tfNoticias o titulo da notícia "i" com um link para mostrar a notícia
_root.tfLista.htmlText += '<a href="asfunction:mostraNoticia,'+i+'">'+titulo+'</a>\n';
// vamos para a próxima notícia
i++;
}
}
// função para mostrar uma notícia selecionada
function mostraNoticia(i:Number):Void {
var titulo:String;
var conteudo:String;
titulo = noticias.firstChild.childNodes.attributes.titulo;
conteudo = noticias.firstChild.childNodes.firstChild.nodeValue;
// Mostramos a notícia
tfConteudo.htmlText = '<b>'+titulo+'</b><br><br>'+conteudo;
}
//
// carregamos o arquivo noticias.xml
noticias.load("noticias.xml");
// cria o objeto xml que vai carregar o arquivo noticias.xml
var noticias:XML = new XML();
// "dizemos" para o objeto noticias que ignore os espaços em branco entre as tags
noticias.ignoreWhite = true;
// definimos o evento que será disparado quando o objeto “noticias” terminar de carregar as notícias
noticias.onLoad = function(sucesso:Boolean) {
// se "sucesso" for verdadeiro significa que o arquivo foi carregado e podemos mostrar o conteúdo dele
if (sucesso) {
listarNoticias();
} else {
// avisa que ocorreu algum erro durante o carregamento
trace("erro ao carregar o arquivo noticias.xml");
}
};
_root.createTextField("tfLista", _root.getNextHighestDepth(), 5, 5, 120, 390);
_root.createTextField("tfConteudo", _root.getNextHighestDepth(), 130, 5, 360, 390);
_root.tfLista.border = true
_root.tfLista.background = true;
_root.tfLista.color = 0x000000
_root.tfLista.html = true
_root.tfLista.multiline = true
_root.tfLista.selectable = false
//
_root.tfConteudo.border = true
_root.tfConteudo.background = true;
_root.tfConteudo.color = 0x000000
_root.tfConteudo.html = true
_root.tfConteudo.multiline = true
_root.tfConteudo.wordWrap = true
_root.tfConteudo.selectable = true
// função para mostrar as notícias carregadas
function listarNoticias():Void {
// variáveis temporárias
var i:Number = 0;
var titulo:String;
var totalNoticias:Number = noticias.firstChild.childNodes.length;
// definimos como "" o "tfLista" para tirar algum texto que não deva estar ali
_root.tfLista.htmlText = "";
// aqui nos fazemos um loop para colocar os títulos de cada notícia no "tfLista" e definimos o link
while (i<totalNoticias) {
// achamos o titulo na notícia "i"
titulo = noticias.firstChild.childNodes.attributes.titulo;
// inserimos no tfNoticias o titulo da notícia "i" com um link para mostrar a notícia
_root.tfLista.htmlText += '<a href="asfunction:mostraNoticia,'+i+'">'+titulo+'</a>\n';
// vamos para a próxima notícia
i++;
}
}
// função para mostrar uma notícia selecionada
function mostraNoticia(i:Number):Void {
var titulo:String;
var conteudo:String;
titulo = noticias.firstChild.childNodes.attributes.titulo;
conteudo = noticias.firstChild.childNodes.firstChild.nodeValue;
// Mostramos a notícia
tfConteudo.htmlText = '<b>'+titulo+'</b><br><br>'+conteudo;
}
noticias.load("noticias.xml");


Cadastre-se
© 2005 - 2008 - Oficina da Net - v 3.0 - É proibida a reprodução parcial ou completa do conteúdo deste site sem autorização por escrito. Resolução adequada: 1024x768px.
Bruno, usei acentuação mas o arquivo não reconhece ou não lê. Tem jeito? Abs.
Publicado em: 20/05/2008 - 09:21
O link para o arquivo já está no artigo, ele está bem abaixo do "Anúncios Google". Ele está meio escondido mesmo. :]
Publicado em: 30/08/2007 - 09:15
parece legal, poe um link para download completo!
Publicado em: 29/08/2007 - 22:24