Question : thumbnail slider click through to url help

I have an image slider that slides in images brought in through xml when you scroll over it, and you're supposed to be able to click on the images and go to a different url for each, but whichever image you click on, it takes you to the last url in the xml document. What am I doing wrong? How do I get it to go to the right url? Here is my code and xml code and you can view the swf here (roll your mouse over the main image).
http://www.kelliegraphicdesign.com/jsa/home.html

Also as a sub question: Is there a way to make it so that it only scrolls when your mouse is over the image area, not anywhere else on the screen?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
/******************************************
Data Typing and Instantiations
******************************************/
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
 
/******************************************
load Method
******************************************/
xmlLoader.load(new URLRequest("homeflash.xml"));
 
/******************************************
Complete Event
******************************************/
function LoadXML(e:Event):void {
	xmlData = new XML(e.target.data);
	//trace(xmlData); 
	var xpos:Number = 0;
	for (var i:int = 0; i < xmlData.project.length(); i++) {
		trace("------------ project " + i+" ------------");
		trace("imageName: " + xmlData.project.imageName.text()[i]);
		trace("theURL: " + xmlData.project.theURL.text()[i]);
		//Create an object for each project and put it in the container
		var newTitle:MovieClip = new myTitle();
		container.addChild(newTitle);
		//image
		var request:URLRequest = new URLRequest("homegallery/"+xmlData.project.imageName.text()[i]);
		var loader:Loader = new Loader()
		loader.load(request);
		newTitle.placeholder.addChild(loader);
		newTitle.placeholder.buttonMode = true;
		//Position each one to the right of the previous one
		newTitle.x = xpos;
		xpos = xpos + newTitle.width;
		//add button click
		var theURL:URLRequest = new URLRequest(xmlData.project.theURL.text()[i]);
		function gotoSite(event:MouseEvent):void {
			navigateToURL((theURL), "_self");
		}
		newTitle.addEventListener(MouseEvent.CLICK, gotoSite);
	}
}
 
 
 
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
 
 
 
 
/****************************************** 
Timer Event
******************************************/
var containerTimer:Timer=new Timer(10);
containerTimer.addEventListener(TimerEvent.TIMER, movecontainer);
function movecontainer(myevent:TimerEvent):void {
	//distanceToTravel is the mouse position minus the center of the stage. 
	//Right side = positive number.
	//Left side = negative number.
	var distanceToTravel = this.mouseX-300;
	//The closer the mouse is to the center, the slower 
	//it moves because there's less added or subtracted.
	container.x -= distanceToTravel/40;
	//If its' too far to the left or right then stop it.
	var leftBounds = (container.width -497)*-1;
	if (container.x0) {
		container.x = 0;
	}
}
containerTimer.start();
 
 
///Here is the XML:


	
		blank.gif
		http://www.kelliegraphicdesign.com/jsa
	
	
		mtn.jpg
		http://www.kelliegraphicdesign.com/jsa/portfolio/portfolio-mountain.html
	
	
		des.jpg
		http://www.kelliegraphicdesign.com/jsa/portfolio/portfolio-desert.html
	
	
		urb.jpg
		http://www.kelliegraphicdesign.com/jsa/portfolio/portfolio-urban.html
	
	
		com.jpg
		http://www.kelliegraphicdesign.com/jsa/portfolio/portfolio-community.html
	
	
		grn.jpg
		http://www.kelliegraphicdesign.com/jsa/portfolio/portfolio-green.html
	
	
		eat.jpg
		http://www.kelliegraphicdesign.com/jsa/portfolio/portfolio-eat.html
	
	
		ply.jpg
		http://www.kelliegraphicdesign.com/jsa/portfolio/portfolio-play.html
	
	
		wrk.jpg
		http://www.kelliegraphicdesign.com/jsa/portfolio/portfolio-work.html
	
	
		pln.jpg
		http://www.kelliegraphicdesign.com/jsa/portfolio/portfolio-plan.html
	

Open in New Window Select All

Answer : thumbnail slider click through to url help

You need to associate you rmovieclip with the url variable. You can do this in some ways. Let's do it with a class.

Create a new actionscript file and copy the code below :

package{
     import flash.display.*;
     public class MyTitle extends MovieClip{
            public var myURL:String;
     }
}

Save in the same folder as your fla and name it MyTitle.as .
Now in your fla file, go to the library , right-click the myTitle movieClip, and choose Linkage...
In linkage window, check Export for Actionscript option.
In the Class field, put MyTitle

What we did: we created a class to control your myTitle mc, and added to it a new property called myURL.
Now in your code do replace the LoadXML function with the one in the snippet:

that should work fine



1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
function LoadXML(e:Event):void {
	xmlData = new XML(e.target.data);
	//trace(xmlData); 
	var xpos:Number = 0;
	for (var i:int = 0; i < xmlData.project.length(); i++) {
		trace("------------ project " + i+" ------------");
		trace("imageName: " + xmlData.project.imageName.text()[i]);
		trace("theURL: " + xmlData.project.theURL.text()[i]);
		//Create an object for each project and put it in the container
		var newTitle:MovieClip = new myTitle();
		container.addChild(newTitle);
		//image
		var request:URLRequest = new URLRequest("homegallery/"+xmlData.project.imageName.text()[i]);
		var loader:Loader = new Loader()
		loader.load(request);
		newTitle.placeholder.addChild(loader);
		newTitle.placeholder.buttonMode = true;
		//Position each one to the right of the previous one
		newTitle.x = xpos;
		xpos = xpos + newTitle.width;
		//add button click
		newTitle.myURL = xmlData.project.theURL.text()[i];
		function gotoSite(event:MouseEvent):void {
                           
                           var theURL:URLRequest = new URLRequest(MyTitle(event.currentTarget).myURL);
			navigateToURL((theURL), "_self");
		}
		newTitle.addEventListener(MouseEvent.CLICK, gotoSite);
	}
}
Open in New Window Select All
Random Solutions  
 
programming4us programming4us