PDA

View Full Version : Linking - I can't make it work



Macro-design
May 12th, 2005, 05:26 AM
I've been working on our new website, and in our portfolio I want image, text and a link button. It all works except from the link.

When I press the link button it links to the last item - even though item 2 ( out of 3 ) is pressed.

It's votes thumbnail scroller thing - but I've had the problem with linking several times, in other projects too.

My AS looks like:
MovieClip.prototype.easeX = function(x) {
this.onEnterFrame = function() {
this._x = Math.ceil(x-(x-this._x)/1.35);
if (Math.abs(x-this._x)<=1) {
delete this.onEnterFrame;
this._x = Math.ceil(x);
}
};
};
images = new Array();
xml_file = "projekter.xml";
xmlload = new XML();
xmlload.ignoreWhite = true;
xmlload.onLoad = function(ok) {
if (ok) {
count = this.firstChild.childNodes.length;
for (var i = 0; i<count; i++) {
curNode = this.firstChild.childNodes[i];
images[i] = {path:curNode.childNodes[0].firstChild.nodeValue, link:curNode.childNodes[1].firstChild.nodeValue, firmaNavn:curNode.childNodes[2].firstChild.nodeValue, imgText:curNode.childNodes[3].firstChild.nodeValue, siteLink:curNode.childNodes[4].firstChild.nodeValue};
}
boot();
} else {
trace("Could not load "+xml_file+".");
}
};
xmlload.load(xml_file);
// ------------------------------------------------------------
spacing = 100;
boot = function () {
for (var i = 0; i<images.length; i++) {
mc = container.attachMovie("thumbMC", "thumb"+i, i);
mc._x = i*(60+spacing);
mc.path = images[i].path;
mc.link = images[i].link;
mc.firmaNavn = images[i].firmaNavn;
mc.finalText = images[i].imgText;
mc.siteLink = images[i].siteLink;
_parent.picture.loadMovie(images[0].link);
_parent.firmaNavn_txt.text = images[0].firmaNavn;
_parent.imageText.text = images[0].imgText;
_parent.siteLink_txt.text = images[0].siteLink;
var linkSite = images[i].siteLink;
}
linkBtn.onPress = function() {
getURL(linkSite);
};
setRollOver();
};
setRollOver = function () {
this.onEnterFrame = function() {
if (this.mask.hitTest(_root._xmouse, _root._ymouse)) {
slideMenu();
}
};
};
slideMenu = function () {
diff = _root._xmouse-this._x;
scale = diff*100/this.mask._width;
target = -scale*(this.container._width-this.mask._width)/100;
this.container.easeX(target);
};

If anybody could help, I would really appreciate it, because it's the last thing I need before that section is done.

Thanks, Morten

scotty
May 12th, 2005, 05:59 AM
boot = function () {
for (var i = 0; i<images.length; i++) {
mc = container.attachMovie("thumbMC", "thumb"+i, i);
mc._x = i*(60+spacing);
mc.path = images[i].path;
mc.link = images[i].link;
mc.firmaNavn = images[i].firmaNavn;
mc.finalText = images[i].imgText;
mc.siteLink = images[i].siteLink;
mc.onPress = function() {
// here you're 'inside' mc so you can refer to
// this.path, this.firmaNavn etc
getURL(this.siteLink);
};
_parent.picture.loadMovie(images[0].link);
_parent.firmaNavn_txt.text = images[0].firmaNavn;
_parent.imageText.text = images[0].imgText;
_parent.siteLink_txt.text = images[0].siteLink;
}
setRollOver();
};

?

scotty(-:

Macro-design
May 12th, 2005, 06:20 PM
Hmmm... I works, but not as it was supposed to. What I wanted, was to have it get the url when linkBtn is pressed. I guess it's some stupid thing I've forgotten, but I just can't seem to find out what it is.

scotty
May 13th, 2005, 02:49 AM
But what url?

scotty(-:

glkngs
May 13th, 2005, 04:05 AM
For each time you loop in your boot function, you assign the linkSite var to somthing different. You have to make different vars for each link.
I would post an example, but im having a hard time understanding the code completely. Do you have a link to the sektion your working on?

scotty
May 13th, 2005, 05:14 AM
glkngs, you're right, that's why I thought that each thumbnail had its own link (see my code) but I don't understand what Macro_design wants with the linkBtn...

scotty(-:

glkngs
May 13th, 2005, 06:28 AM
I just had a look at your site: http://www.macro-design.org/
You seem to be able to access all the other data from the xml, such as description and stuf. How come you cant refer to the siteLink var, the same way?

Macro-design
May 13th, 2005, 05:26 PM
I'll try explain a little better, I just made a new website - www.macro-design.org.

In the "projekter" there's an example - the idea is to make an invisible button over the textBox that writes the link.

Now I've tried referring to it, in the same way, but I just can't make it work, that's why I'm so confused, because it should work, but it just doesn't.

When I used your coding, Scotty, then when the thumbnail image was pressed it linked to the site. The idea is to have som text, image and then my link button loading - depending on the thumbnail pressed ofcourse. And when I create a button that will send the user to the project they've entered, it doesn't work.

Hope you understand, because it's proberly som little stupid line of coding, but I just can't figure it out. If you doesn't understand what I'm talking about, I can upload the .fla, but then I just doesn't learn anything, and I guess that's the idea with this forum. Anyways, what I'm trying to say is, that I can upload the .fla if it's wanted.

thanks, Morten

scotty
May 13th, 2005, 05:47 PM
I'm starting to understand it :lol:
try

var linkSite;
boot = function () {
for (var i = 0; i<images.length; i++) {
mc = container.attachMovie("thumbMC", "thumb"+i, i);
mc._x = i*(60+spacing);
mc.path = images[i].path;
mc.link = images[i].link;
mc.firmaNavn = images[i].firmaNavn;
mc.finalText = images[i].imgText;
mc.siteLink = images[i].siteLink;
mc.onPress = function() {
// here you're 'inside' mc so you can refer to
// this.path, this.firmaNavn etc
_root.linkSite=this.siteLink;
};
_parent.picture.loadMovie(images[0].link);
_parent.firmaNavn_txt.text = images[0].firmaNavn;
_parent.imageText.text = images[0].imgText;
_parent.siteLink_txt.text = images[0].siteLink;
}
linkBtn.onPress = function() {
getURL(_root.linkSite);
};
setRollOver();
};
If it doesn't work post your fla?

scotty(-:

Macro-design
May 14th, 2005, 02:31 PM
Hi, now, this does work, but the rest of the functions that worked before, doesn't work anymore.

here's the .fla - http://www.macro-design.org/test/projekter.fla/

and the xml is - http://www.macro-design.org/projekter.xml/

You can see what I tried to explain above when you download the file, and thanks, I really appreciate your help - you're simply just the best.

scotty
May 14th, 2005, 05:25 PM
Both links give me a 404....

scotty(-:

Macro-design
May 15th, 2005, 03:54 PM
Are you sure, if you could please try again it would be a great help, because I've never experienced downtime on our server.

If it still gives you a 404 - please let me know

999
May 15th, 2005, 04:19 PM
Try the links without the forward slash on the end. ;)

scotty
May 15th, 2005, 04:48 PM
Thanks ditchhopper ;)

The code I gave you before was almost right, except that teh code wasn't in _root...
This one works

var linkSite;
boot = function () {
for (var i = 0; i<images.length; i++) {
mc = container.attachMovie("thumbMC", "thumb"+i, i);
mc._x = i*(60+spacing);
mc.path = images[i].path;
mc.link = images[i].link;
mc.firmaNavn = images[i].firmaNavn;
mc.finalText = images[i].imgText;
mc.siteLink = images[i].siteLink;
mc.onPress = function() {
// here you're 'inside' mc so you can refer to
// this.path, this.firmaNavn etc
linkSite = this.siteLink;
linkBtn.onPress = function() {
getURL(linkSite, "_blank");
};
};
_parent.picture.loadMovie(images[0].link);
_parent.firmaNavn_txt.text = images[0].firmaNavn;
_parent.imageText.text = images[0].imgText;
_parent.siteLink_txt.text = images[0].siteLink;
}
setRollOver();
};
I've put the code inside the mc.onPress to prevent clicking on linkBtn while linkeSite isn't defined :)

scotty(-:

Macro-design
May 15th, 2005, 06:47 PM
Sorry for being so difficult but it didn't change anything, for me at least. Doesn't know why, but when I click the thumbnails the text and image doesn't change just like before. I don't know if you can upload the file or something?


thanks, Morten

scotty
May 15th, 2005, 07:04 PM
My bad, I only looked at the linkBtn...
Here it works as it should (I hope :lol: )

var linkSite;
boot = function () {
for (var i = 0; i<images.length; i++) {
mc = container.attachMovie("thumbMC", "thumb"+i, i);
mc._x = i*(60+spacing);
mc.path = images[i].path;
mc.link = images[i].link;
mc.firmaNavn = images[i].firmaNavn;
mc.finalText = images[i].imgText;
mc.siteLink = images[i].siteLink;
mc.onPress = function() {
linkSite = this.siteLink;
_parent.picture.loadMovie(this.link);
_parent.firmaNavn_txt.text = this.firmaNavn;
_parent.imageText.text = this.finalText;
_parent.siteLink_txt.text = this.siteLink;
};
_parent.picture.loadMovie(images[0].link);
_parent.firmaNavn_txt.text = images[0].firmaNavn;
_parent.imageText.text = images[0].imgText;
_parent.siteLink_txt.text = images[0].siteLink;
linkSite = images[0].siteLink;
linkBtn.onPress = function() {
getURL(linkSite, "_blank");
};
}
setRollOver();
};

scotty(-:

glkngs
May 16th, 2005, 09:38 AM
I just noticed, if you use Scotty's code, you shold remove the code in the onRelease function in the thumb the you are attaching from the library.. otherwise you'll end up having the same code on both the onPress and onRelease :geek:

Macro-design
May 16th, 2005, 11:29 AM
Okay, thanks for all the help, I'll take a look at it, when I get home and let you know if it works - which it properly does this time :)

scotty
May 16th, 2005, 12:37 PM
Good point glkngs, I never looked at the thumb it self...

scotty(-:

Macro-design
May 16th, 2005, 03:21 PM
It works, thanks for the help, and I think that I understand the code :)

@glkngs

you got the eyes of a turtle

Macro-design
May 16th, 2005, 03:22 PM
I mean hawk of course

glkngs
May 16th, 2005, 03:38 PM
thanks!
Btw, who are you guys? part time agency? where are you located?

Macro-design
May 17th, 2005, 12:18 PM
We've just started up our own company in Denmark - Værløse to be more specific. It's part time at the moment, I create the graphics and coding, and the other two in the company takes care of documents and business meeting - though I also participate, the other two do all the pre-work. Background check on the company's, ect.

[swiching to danish] kan se du også er fra danmark, du er meget velkommen til at give os din mail, da vi godt kan få brug for noget freelance arbejde - skriv til mortenkh@gmail.com, hvis du er interesseret.[/swiching to danish]