Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Hyperlink

Status
Not open for further replies.

csr500

Programmer
Sep 11, 2007
6
0
0
Hello

I have searched for the answer to this anc cant seem to find the correct answer. This is my first ever post and I am new to XML so please do not blind me with science.

I have a flash document which takes an XML file for the content, I would like to insert a hyperlink into the text and I have inserted this code into the XML file.

<a href="Home.html">HOME</a>

Instead of a hyperlink called home linking to home.html, I simply get the code written out above.

I am sure I have done something very silly, but I cant spot it, as I am not really an expert.

Any help on this matter would be very much appreciated.

Cameron
 
Hi Cameron,

If you have data which contains lots of <, > and & characters you can use a CDATA section which effectively tells the XML parser to ignore that part of the file.
Code:
<MyContainerElement><![CDATA[<a href="Home.html">HOME</a>]]></MyContainerElement>

See W3Schools for more info:
Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
How are you displaying the text in flash?

Try using ".nodeValue" for the appropriate XML node.

Jon

"I don't regret this, but I both rue and lament it.
 
Thank you both for responding so quickly however I am still a little stuck.

I dont understand how to use CDATA correctly and when I try to imput it I seem to to loose the picture I have.

Below is a copy of the xml file I have.

<?xml version="1.0" encoding="iso-8859-1"?>

<icons>

<icon image ="images/icon1.png" tooltip="Samsung BlackJack" content = "The Samsung BlackJack is a slim, stylish mobile entertainment and organizational powerhouse. It plays: with Cellular Video and AT&T Mobile Music - exclusive TV content and your digital tunes. And it works: with Microsoft® Windows Mobile 5, Mobile Office TM applications, personal and corporate email and attachment support. And it does it all at break-neck 3G speeds. Only from AT&T."/>

</icons>

I would like to put the only from AT&T as a hyperlink to the ATT website. I dont actually know where to put the CDATA start and end brackets. Sorry for being so stupid.

Secondly I am not actually sure how the text is being displayed. I simply call it like so

xml.load("icons.xml");

in my flash actionscript.

Please please please help me out

Cameron
 
You'll need to find where and how in the flash the text is being displayed. It will need to be html text, something like:

myTextfield.html = true;
myTextfield.htmlText = theText;

Jon

"I don't regret this, but I both rue and lament it.
 
Here is the action script:

import mx.utils.Delegate;
import mx.transitions.Tween
import mx.transitions.easing.*;
#include "mc_tween2.as"

//this._lockroot = true;

var numOfItems:Number ;
//size of circle
var radiusX:Number = 275;
//circle height
var radiusY:Number = 95;
var centerX:Number = 390;
var centerY:Number = Stage.height/2;
//controls circle spin
var speed:Number = 0.005;
var perspective: Number = 80;
var home:MovieClip = this;
theText._alpha = 0;

//tool tip is loading into level 500
var tooltip:MovieClip = this.attachMovie("tooltip","tooltip",500);
tooltip._alpha = 0;

var xml:XML = new XML();
xml.ignoreWhite = true;

xml.onLoad = function()
{
var nodes = this.firstChild.childNodes;
numOfItems = nodes.length;
for(var i=0;i<numOfItems;i++)
{
var t = home.attachMovie("item", "item"+i,i+1);
t.angle = i *((Math.PI*2)/numOfItems);
t.onEnterFrame = mover;
t.toolText = nodes.attributes.tooltip;
t.content = nodes.attributes.content;
t.icon.inner.loadMovie(nodes.attributes.image);
t.r.inner.loadMovie(nodes.attributes.image);
t.icon.onRollOver = over;
t.icon.onRollOut = out;
t.icon.onRelease = released;

}
}

function over()
{
home.tooltip.tipText.text = this._parent.toolText;
home.tooltip._x = this._parent._x;
home.tooltip._y = this._parent._y - this._parent.height/2;
home.tooltip.onEnterFrame = Delegate.create(this,moveTip);
new Tween(home.tooltip, "_alpha", Strong.easeIn, 0, 100, 0.50, true);
}
function out()
{
delete home.tooltip.onEnterFrame;
new Tween(home.tooltip, "_alpha", Strong.easeIn, 100, 0, 0.50, true);
home.tooltip._alpha = 0;
}

function released ()
{
home.tooltip._alpha = 0;
for(var i=0;i<numOfItems;i++)
{
var t: MovieClip = home["item"+i]
t.xPos = t._x;
t.yPos = t._y;
t.theScale = t._xscale;
delete t.icon.onRollOver;
delete t.icon.onRollOut;
delete t.icon.onRelease;
delete t.onEnterFrame;
//!= means if not equal to
if(t != this._parent)
{
var tw:Tween = new Tween(t,"_xscale",Strong.easeOut,t._xscale,0,1,true);
var tw2:Tween = new Tween(t,"_yscale",Strong.easeOut,t._yscale,0,1,true);
var tw3:Tween = new Tween(t,"_alpha",Strong.easeOut,100,0,1,true);
}
else
{
//change size of enlarged icon
var tw:Tween = new Tween(t,"_xscale",Strong.easeOut,t._xscale,100,1,true);
var tw2:Tween = new Tween(t,"_yscale",Strong.easeOut,t._yscale,100,1,true);
// Change x and y position of enlarged icon
var tw3:Tween = new Tween(t,"_x",Strong.easeOut,t._x,132,1,true);
var tw4:Tween = new Tween(t,"_y",Strong.easeOut,t._y,300,1,true);
var tw5:Tween = new Tween(theText,"_alpha",Strong.easeOut,0,100,1,true);
theText.text = t.content;
var s:Object = this;
tw.onMotionStopped = function()
{
s.onRelease = unReleased;
}
}
}
}

function unReleased()
{
delete this.onRelease;
var tw:Tween = new Tween(theText,"_alpha",Strong.easeOut,100,0,1,true);
for(var i=0;i<numOfItems;i++)
{
var t: MovieClip = home["item"+i]
//!= means if not equal to
if(t != this._parent)
{
var tw:Tween = new Tween(t,"_xscale",Strong.easeOut,0,t.theScale,1,true);
var tw2:Tween = new Tween(t,"_yscale",Strong.easeOut,0,t.theScale,1,true);
var tw3:Tween = new Tween(t,"_alpha",Strong.easeOut,0,100,1,true);
var tw4:Tween = new Tween(t,"_y",Strong.easeOut,t._y,t.yPos,1,true);
}
else
{
var tw:Tween = new Tween(t,"_xscale",Strong.easeOut,100,t.theScale,1,true);
var tw2:Tween = new Tween(t,"_yscale",Strong.easeOut,100,t.theScale,1,true);
var tw3:Tween = new Tween(t,"_x",Strong.easeOut,t._x,t.xPos,1,true);
var tw4:Tween = new Tween(t,"_y",Strong.easeOut,t._y,t.yPos,1,true);
tw.onMotionStopped = function()
{
for(var i=0;i<numOfItems;i++)
{
var t:MovieClip = home["item"+i];
t.icon.onRollOver = Delegate.create(t.icon,over);
t.icon.onRollOut = Delegate.create(t.icon,out);
t.icon.onRelease = Delegate.create(t.icon,released);
t.onEnterFrame = mover;
}
}
}
}
}



function moveTip()
{
home.tooltip._x = this._parent._x;
home.tooltip._y = this._parent._y - this._parent._height/2;
}

xml.load("icons.xml");

function mover ()
{
this._x = Math.cos(this.angle) * radiusX + centerX;
this._y = Math.sin(this.angle) * radiusY + centerY;
var s:Number = (this._y - perspective)/ (centerY+radiusY-perspective);
this._xscale = this._yscale = s * 100;
this.angle += this._parent.speed;
this.swapDepths(Math.round(this._xscale) + 100);

}

this.onMouseMove = function()
{
///set spin speed, higher number = slower
speed = (this._xmouse-centerX)/9500;
}


Sorry for just pasting the whole lot in, but I am sure that I will find the wrong thing and just paste that in.

Thank you for you time
 
This is the important bit:
Code:
xml.onLoad = function()
{
    var nodes = this.firstChild.childNodes;
    numOfItems = nodes.length;
    for(var i=0;i<numOfItems;i++)
    {
        var t = home.attachMovie("item", "item"+i,i+1);
        t.angle = i *((Math.PI*2)/numOfItems);
        t.onEnterFrame = mover;
        t.toolText = nodes[i].attributes.tooltip;
        t.content = nodes[i].attributes.content;
        .....
It's dynamically creating the "item" movie from the library and setting t.content to the content attribute of the xml. You'll need to look at the "item" movie clip and see what happens with the content variable.

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top