hello, I have JUST joined this group and I need help.
I want to turn a XML caption into a clickable link.
Here is my XML file: Iwant to have “Visit” be clickable and go to the website listed.
<GALLERY COLUMNS=“4” XPOSITION=“350” YPOSITION=“199” WIDTH=“41” HEIGHT=“34” SPEED=“2”>
<IMAGE FULL=“full_images/image1.jpg” THUMB=“thumbs/thumb1.jpg” NAME=“Prospective Students” DESCRIPTION=“Description Here!”
INFO=“Visit” LINK=“http://www.google.com”/>
</GALLERY>
Here is my actionscript which I got following tutorials on Republic of Code.
Everything works, but I NEED to the INFO node into a clickable link. Can anyone help?
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
var myXML:XML;
var columns:Number; // how many columns for thumbnails
var my_x:Number; //position of the thumbnails along x-axis
var my_y:Number; //position of the thumbnails along y-axis
var my_thumb_width:Number; //width of single thumb
var my_thumb_height:Number; //height of single thumb
var my_total:Number; //number of thumbnails
var my_images:XMLList; //a reference to the list of images to retrieve the URL and title of each image
var my_speed:Number;
var my_link:String;
var myTimer:Timer;
var my_loaders_array:Array = [];
var my_playback_counter:Number = 0;
var my_image_slides:Sprite = new Sprite;
var myName:TextField = new TextField();//variable to display the Name Text
var myNameFormat:TextFormat = new TextFormat(); // controls the size and font style
myNameFormat.font = “Arial”;
myNameFormat.size = 30;
myName.defaultTextFormat = myNameFormat;
myName.textColor=0x00000;
var myDesc:TextField = new TextField();
var myDescFormat:TextFormat=new TextFormat();
myDescFormat.font=“Arial”;
myDescFormat.size=20;
myDesc.defaultTextFormat = myDescFormat;
myDesc.textColor=0x990000;
var myInfo:TextField = new TextField();
var myInfoFormat:TextFormat = new TextFormat();
myInfoFormat.font = “Arial”;
myInfoFormat.size = 12;
myInfoFormat.align = TextFormatAlign.RIGHT; //aligns right to the TextField width (myURL.width)
myInfo.defaultTextFormat = myInfoFormat;
myInfo.textColor = 0x000000;
var container_mc:MovieClip; //variable to display the thumbnails
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest(“GALLERY_NEW.xml”)); //loads the XML file
myXMLLoader.addEventListener(Event.COMPLETE, processXML); //this listens for the Event.COMPLETE which we called processXML.
function processXML(e:Event):void //processing the XML via this function. The code to be triggered must be in this function.
{
var myXML:XML = new XML(e.target.data); // creating an instance of XML Class & assigning the data to the XML file
columns = myXML.@COLUMNS;
my_x = myXML.@XPOSITION;
my_y = myXML.@YPOSITION;
my_thumb_width = myXML.@WIDTH;
my_thumb_height = myXML.@HEIGHT;
my_images = myXML.IMAGE; //assigning thumbnail tag in XML file to variable thumbimages
my_total = my_images.length(); //refers to the total number of thumbnails in XML file
my_speed = myXML.@SPEED;
my_link = myXML.@LINK;
/* these functions are automatically called on upload */
createContainer();//this function gets called with the processXML() function is called
callThumbs(); //call the function callThumbs on upload
callFull(null);//call the function CallFull on upload
}
function createContainer():void //this function is making a container to display the thumbnails
{
container_mc = new MovieClip();
container_mc.x = my_x; //position the thumbnails on the x-axis using my_x
container_mc.y = my_y; //positons the thumbnails on the y-axis using my_y
addChild(container_mc); //adding MovieClip to display list
/registering mouse click to the thumbnails. register the event listerner to the container_mc, eliminates repeating for every thumbnail./
container_mc.addEventListener(MouseEvent.CLICK, callFull);
container_mc.buttonMode = true; //activates the Finger Cursor for the thumbnails
/add hover effect back after taking it away call in the function onOver*/
container_mc.addEventListener(MouseEvent.MOUSE_OVER, onOver);
container_mc.addEventListener(MouseEvent.MOUSE_OUT, onOut);
}
//function = call Thumbs, load the thumbnails; you need the Loader Class to load images
function callThumbs():void
{
for (var i:Number = 0; i < my_total; i++) //thumbtotal = total of thumbnails
{
var thumb_url = my_images*.@THUMB; //i cycles thru the XML elements & retrieves URL by using @ operator
//thumbimages = thumbnail in XML file; storing the URL of thumbnails in local variable thumb_url
var thumb_loader = new Loader();
// create new temporary instance of Loader Class using “new” and then instantly load the thumb image using .load()
thumb_loader.load(new URLRequest(thumb_url));
thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded); //show thumbnails when loaded, register the Event.COMPLETE, by using .addEventListerner, special listerner = thumbloaded
thumb_loader.x = (my_thumb_width+10)i; //the width of each thumbnail = my_thumb_width so multiply by “i” my_thumb_widthi to get the thumbnails side by side. To get space (my_thumb_width+10)*i
thumb_loader.name = i; //this saves the name of each thumbnail
myName.text = my_images[0].@NAME;
myDesc.text = my_images[0].@DESCRIPTION; myInfo.text = my_images[0].@INFO;
}
}
function thumbLoaded(e:Event):void
{
var my_thumb:Loader = Loader(e.target.loader);
container_mc.addChild(my_thumb);
}
/adds a hover to the thumbnails/
function onOver (e:MouseEvent):void
{
var my_thumb:Loader = Loader(e.target);
my_thumb.alpha = 0.4; //fades 60%
}
function onOut (e:MouseEvent):void
{
var my_thumb:Loader = Loader (e.target);
my_thumb.alpha = 1;
}
/adds the item 1 text as default on upload/
// calling the full images
function callFull(e:MouseEvent):void
{
var full_loader:Loader = new Loader(); //full_loader references the full Image
var full_url;
if (e != null)
{
full_url = my_images[e.target.name].@FULL;
myName.text = my_images[e.target.name].@NAME;
myDesc.text = my_images[e.target.name].@DESCRIPTION;
myInfo.text = my_images[e.target.name].@INFO;
}
else
{
full_url = my_images[0].@FULL;
}
full_loader.load(new URLRequest(full_url));
full_loader.contentLoaderInfo.addEventListener(Event.INIT, fullLoaded);
}
function fullLoaded(e:Event):void
{
var my_loader:Loader = Loader(e.target.loader);
addChild(my_loader);
my_loader.x=7;
my_loader.y=2;
new Tween(my_loader,“alpha”,Strong.easeOut,0,1,1,true);
addChild(myName);
myName.x=5;
myName.y=200;
myName.width=300;
addChild(myDesc); //calls the DESCRIPTION attribute
myDesc.x=5;
myDesc.y=245;
myDesc.width=566;
myDesc.height=100;
myDesc.wordWrap=true;
addChild(myInfo);
myInfo.x = 5;
myInfo.y = 289;
myInfo.width = 548; //width of the myURL TextField
}