Creating a Link in XML for Flash
Um hi people. I hope this isn't too irritating but I was just wondering if you could help me with something ^.^;;;
Anyway, I'm working on making a trading centre type code. This is set up so that the XML controls the sprite shown and the information about the Pokemon.
Beneath this is a 'contact trainer' button.
Now so far I have everything working apart from the 'contact trainer' button as I can't work out how.
I based this off a kirrupa(sp is it one r or two -muse-) XML flash photo gallery but customized it for my own use after breaking the kirrupa one many times in testing to get used to it.
So I was wondering if anyone could help me do this final bit of setting up?
The XML is:
Code:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<images>
<pic>
<image>http://images2.wikia.nocookie.net/__cb20081023172723/pokemon/images/d/d4/MissingNo.GhostSprite.png</image>
<caption>No pokemon here</caption>
<link>http://</link>
</pic>
</images>
and I've included my flash file. This has been coded in CS3 so far.
Any help would be greatful.
As an aside I've also encountered the problem of XML not updating until I've hard refreshed the XML itself, is there any way of combating this? Everything is hosted on my ripway account in the same part.
Attached Files
Senior Member
Im not really sure what your all asking..
but for the LINKS int he XML.. maybe try wrapping in CDATA tags?
(also make sure on the Flash side you are using HTML enabled text fields.. and using htmlText = instead of just text =.....)
<link><![CDATA[http://www.google.com]]></link>
how are you handling in on the Flash side of things?
what do you mean by handling in? -very newb ^.^;;;-
Senior Member
sorry, typo..
handling it*
meaning.. on the flash side of things..
when you import your XML data..
and you get the the <LINK> node..
your going to get the text as you see it in the XML file (exactly as you see it between the CDATA tags)
but in flash thats just text..
you need to take that text and use it in an getURL() function somewhere.
Okay - basically my XML code is as listed above.
The AS powering it which has had one of my college tutors try something that worked when i just tested it on the computer is:
Code:
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
description = [];
url = [];
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;
url[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
}
firstImage();
} else {
content = "file not loaded!";
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("http://h1.ripway.com/Kaida/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();
};
contact_btn.onRelease = function() {
gotoURL();
};
// ///////////////////////////////////
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 gotoURL() {
getURL(url[p]);
}
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;
}
Senior Member
whats the question?
you need to wrap the data/url in the XML file in CDATA tags..like I posted above.
so what is happening so far?
-go to try that-
I've made that change.
The site is: http://forum.resortisle.info
Even with the CDATA tags around the link its still not registering on the 'contact trainer' button.
Can you explain if i need to then add code onto the button itself to link this with the code already written to incorporate the XML in?
Actionscript Code:
function loadXML( loaded ) { if ( loaded ) { _root .getURLLink = ( this .firstChild .childNodes [ 0 ] .childNodes [ 2 ] .firstChild .nodeValue ) ;} } function nextImage( ) { if ( p< ( total-1 ) ) { p++; if ( loaded == filesize) { _root .getURLLink = ( xmlNode .childNodes [ p] .childNodes [ 2 ] .firstChild .nodeValue ) ; } } } function prevImage( ) { if ( p> 0 ) { p--; _root .getURLLink = ( xmlNode .childNodes [ p] .childNodes [ 2 ] .firstChild .nodeValue ) ; } } function gotoURL( ) { getURL ( _root .getURLLink ,_blank) ; }
XML:
PHP Code:
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <images> <pic> <image>http://images2.wikia.nocookie.net/__cb20081023172723/pokemon/images/d/d4/MissingNo.GhostSprite.png</image> <caption>No pokemon here</caption> <link><![CDATA[http://www.yourDomainName.com]]></link> </pic> </images>
Poltuda
Last edited by poltuda; 10-18-2010 at 05:42 PM .
Poltuda, can you explain where the ActionScript Code needs to go/replace please? -a bit confused still-
I have already mentioned those section where you need to change or add
Actionscript Code:
function gotoURL( ) { getURL ( _root .getURLLink ,_blank) ; } function nextImage( ) { if ( p< ( total-1 ) ) { p++; if ( loaded == filesize) { picture._alpha = 0 ; picture.loadMovie ( image[ p] , 1 ) ; _root .getURLLink = ( xmlNode .childNodes [ p] .childNodes [ 2 ] .firstChild .nodeValue ) ; desc_txt.text = description[ p] ; picture_num( ) ; } } } function prevImage( ) { if ( p> 0 ) { p--; picture._alpha = 0 ; picture.loadMovie ( image[ p] , 1 ) ; _root .getURLLink = ( xmlNode .childNodes [ p] .childNodes [ 2 ] .firstChild .nodeValue ) ; desc_txt.text = description[ p] ; picture_num( ) ; } } function firstImage( ) { if ( loaded == filesize) { picture._alpha = 0 ; picture.loadMovie ( image[ 0 ] , 1 ) ; _root .getURLLink = ( xmlNode .childNodes [ p] .childNodes [ 2 ] .firstChild .nodeValue ) ; desc_txt.text = description[ 0 ] ; picture_num( ) ; } }
Poltuda
Last edited by poltuda; 10-18-2010 at 05:44 PM .
Okay, I've done all that made them changes n the website itself even after re-embedding it still not working button wise, am I missing something when it works in all situations apart from there?
Okay I fixed it - I changed SameDomain stuff in the embed code to Always
Thank you
Last edited by Kaida; 10-19-2010 at 01:03 AM .
Reason: Fixed the problem
This is the total project
XML Part:
imagesLoad.xml
PHP Code:
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <images name="Images From Library 1"> <pic> <image>http://localhost/images/kresge.jpg</image> <caption><![CDATA[<b>Kresge</b>]]></caption> <description><![CDATA[Description of <b>Kresge</b> <a href ='http://www.youDomainName.com/kresge.html'/><i><font color="#0000FF" size="12">Contact Trainer</font></i></a>]]></description> <link><![CDATA[<a href ='http://www.youDomainName.com/kresge.html'/><i><font color="#0000FF" size="12">Contact Trainer</font></i></a>]]></link> </pic> <pic> <image>http://localhost/images/medialab.jpg</image> <caption><![CDATA[<b>Media Lab</b>]]></caption> <description><![CDATA[Description of <b>Media Lab</b> <a href ='http://www.youDomainName.com/kresge.html'/><i><font color="#0000FF" size="12">Contact Trainer</font></i></a>]]></description> <link><![CDATA[<a href ='http://www.youDomainName.com/kresge.html'/><i><font color="#0000FF" size="12">Contact Trainer</font></i></a>]]></link> </pic> <pic> <image>http://localhost/images/stata.jpg</image> <caption><![CDATA[<b>Stata Center</b>]]></caption> <description><![CDATA[Description of <b>Stata Center</b> <a href ='http://www.youDomainName.com/kresge.html'/><i><font color="#0000FF" size="12">Contact Trainer</font></i></a>]]></description> <link><![CDATA[<a href ='http://www.youDomainName.com/kresge.html'/><i><font color="#0000FF" size="12">Contact Trainer</font></i></a>]]></link> </pic> <pic> <image>http://localhost/images/stata_lobby.jpg</image> <caption><![CDATA[<b>Stata Lobby</b>]]></caption> <description><![CDATA[Description of <b>Stata Lobby</b> <a href ='http://www.youDomainName.com/kresge.html'/><i><font color="#0000FF" size="12">Contact Trainer</font></i></a>]]></description> <link><![CDATA[<a href ='http://www.youDomainName.com/kresge.html'/><i><font color="#0000FF" size="12">Contact Trainer</font></i></a>]]></link> </pic> <pic> <image>http://localhost/images/construction.jpg</image> <caption><![CDATA[<b>Construction</b>]]></caption> <description><![CDATA[Description of <b>Construction</b> <a href ='http://www.youDomainName.com/kresge.html'/><i><font color="#0000FF" size="12">Contact Trainer</font></i></a>]]></description> <link><![CDATA[<a href ='http://www.youDomainName.com/kresge.html'/><i><font color="#0000FF" size="12">Contact Trainer</font></i></a>]]></link> </pic> <pic> <image>http://localhost/images/dome.jpg</image> <caption><![CDATA[<b>The Dome</b>]]></caption> <description><![CDATA[Description of <b>The Dome</b> <a href ='http://www.youDomainName.com/kresge.html'/><i><font color="#0000FF" size="12">Contact Trainer</font></i></a>]]></description> <link><![CDATA[<a href ='http://www.youDomainName.com/kresge.html'/><i><font color="#0000FF" size="12">Contact Trainer</font></i></a>]]></link> </pic> <pic> <image>http://localhost/images/structure.jpg</image> <caption><![CDATA[<b>Structure</b>]]></caption> <description><![CDATA[Description of <b>Structure</b> <a href ='http://www.youDomainName.com/kresge.html'/><i><font color="#0000FF" size="12">Contact Trainer</font></i></a>]]></description> <link><![CDATA[<a href ='http://www.youDomainName.com/kresge.html'/><i><font color="#0000FF" size="12">Contact Trainer</font></i></a>]]></link> </pic> </images>
Actionscript 2 Code:
Actionscript Code:
function loadXML( loaded ) { if ( loaded ) { xmlNode = this .firstChild ; image = [ ] ; title = [ ] ; link = [ ] ; describe = [ ] ; head_txt.html =true ; head_txt.htmlText ="<b><font color='#8F969E'>" + xmlNode .attributes .name +"</font></b>" ; total = xmlNode .childNodes .length ; for ( i=0 ; i< total; i++) { image[ i] = xmlNode .childNodes [ i] .childNodes [ 0 ] .firstChild .nodeValue ; title[ i] = xmlNode .childNodes [ i] .childNodes [ 1 ] .firstChild .nodeValue ; link[ i] = xmlNode .childNodes [ i] .childNodes [ 3 ] .firstChild .nodeValue ; describe[ i] = xmlNode .childNodes [ i] .childNodes [ 2 ] .firstChild .nodeValue ; } firstImage( ) ; } else { content = "file not loaded!" ; } } xmlData = new XML ( ) ; xmlData.ignoreWhite = true ; xmlData.onLoad = loadXML; xmlData.load ( "http://localhost/imagesLoad.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 gotoURL( ) { getURL ( _root .getURLLink , _blank) ;} function nextImage( ) { if ( p< ( total-1 ) ) { p++; if ( loaded == filesize) { picture._alpha = 0 ; picture.loadMovie ( image[ p] ,1 ) ; _root .getURLLink = ( xmlNode .childNodes [ p] .childNodes [ 2 ] .firstChild .nodeValue ) ; title_txt.htmlText = title[ p] +" [ " +link[ p] +" ]" ; main_txt.text = title[ p+1 ] ; describe_txt.html = true ; describe_txt.htmlText = describe[ p] ; if ( p ! = ( total-1 ) ) { //main_txt.html=true; main_txt.htmlText = title[ p+1 ] ; } else { main_txt.htmlText = "<b>This is the last Image</b>" ; } picture_num( ) ; } } else { main_txt.htmlText = "<b>This is the last Image</b>" ; } } function prevImage( ) { if ( p> 0 ) { p--; picture._alpha = 0 ; picture.loadMovie ( image[ p] ,1 ) ; _root .getURLLink = ( xmlNode .childNodes [ p] .childNodes [ 2 ] .firstChild .nodeValue ) ; title_txt.htmlText = title[ p] +" [ " +link[ p] +" ]" ; main_txt.text = title[ p+1 ] ; describe_txt.html = true ; describe_txt.htmlText = describe[ p] ; if ( p ! = 0 ) { //main_txt.html=true; main_txt.htmlText = title[ p-1 ] ; } else { main_txt.htmlText = title[ p] ;//"This is the first Image"; } picture_num( ) ; } else { main_txt.htmlText = "<b>This is the first Image</b>" ; } } function firstImage( ) { if ( loaded == filesize) { picture._alpha = 0 ; picture.loadMovie ( image[ 0 ] ,1 ) ; _root .getURLLink = ( xmlNode .childNodes [ p] .childNodes [ 2 ] .firstChild .nodeValue ) ; title_txt.html = true ; title_txt.htmlText = title[ p] +" [ " +link[ p] +" ]" ; main_txt.html = true ; main_txt.htmlText = title[ p+1 ] ; describe_txt.html = true ; describe_txt.htmlText = describe[ p] ; picture_num( ) ; } } function picture_num( ) { current_pos = p+1 ; pos_txt.text = current_pos+" / " +total;} previous_btn.onRollOver = function ( ) { previous_btn.gotoAndStop ( 2 ) ; if ( p> 0 ) { //main_txt.html=true; main_txt.htmlText = title[ p-1 ] ; } else { main_txt.htmlText = "<b>This is the first Image</b>" ; } } ; previous_btn.onRollOut = function ( ) { previous_btn.gotoAndStop ( 1 ) ; //main_txt.html=true; main_txt.htmlText = title[ p+1 ] ;} ; next_btn.onRollOver = function ( ) { next_btn.gotoAndStop ( 2 ) ; if ( p< ( total-1 ) ) { //main_txt.html=true; main_txt.htmlText = title[ p+1 ] ; } else { main_txt.htmlText = "<b>This is the last Image<b/>" ; } } ; next_btn.onRollOut = function ( ) { next_btn.gotoAndStop ( 1 ) ; if ( p ! = ( total-1 ) ) { //main_txt.html=true; main_txt.htmlText = title[ p+1 ] ; } else { main_txt.htmlText = title[ p-1 ] ; } } ;
And you need the following elements:
Dynamic textField
head_txt
title_txt
pos_txt
describe_txt
main_txt
Static textField
Next
Previous
Movieclips
picture (An empty movieclips to hold the images)
previous_btn and next_btn (movieclips with two frames)
preloader movieclips and inside of it preloader_bar movieclips
Thats ALL
Regards
Poltuda
Last edited by poltuda; 10-19-2010 at 05:59 AM .
The above code I Posted has some added features
Try it
Regards
Poltuda
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width