Log in

View Full Version : AS2.0 - onRelease issue



Tek81
08-27-2008, 03:49 PM
Hi there,
First time poster here.

On to my issue, I have some AS2.0 code pulling in values from XML into my swf and my function that I'm setting for my onRelease is being ran with no interaction at all. Its running in the loop and gives all the correct values, but it just runs on its own without clicking on the images/buttons for the onRelease to take effect. Here is my code for this:


var xmlData:XML = new XML();

xmlData.ignoreWhite = true;

xmlData.onLoad = function ()
{
var nodes = this.firstChild.childNodes;
header.text = nodes[0].attributes.caption;
numOfItems = nodes.length;
for (var i=0;i<numOfItems;i++)
{
var t = home.attachMovie("item","item"+i,i+1);
var url = nodes[0].attributes.urlLoc + nodes[i].attributes.itemid;
t.angle = i * ((Math.PI*2)/numOfItems);
t.icon.inner.loadMovie(nodes[i].attributes.img);
t.onEnterFrame = mover;
t.icon.onRelease = released(url);
}
}

xmlData.load("flashFiles/items.xml");

function released(e)
{
trace(e);
//getURL(e);
}

and the trace results from the code above:


http://www.myurllink.com/tmg_viewitem.asp?itemnbr=412
http://www.myurllink.com/tmg_viewitem.asp?itemnbr=422
http://www.myurllink.com/tmg_viewitem.asp?itemnbr=487
http://www.myurllink.com/tmg_viewitem.asp?itemnbr=499
http://www.myurllink.com/tmg_viewitem.asp?itemnbr=501
http://www.myurllink.com/tmg_viewitem.asp?itemnbr=502
http://www.myurllink.com/tmg_viewitem.asp?itemnbr=506
http://www.myurllink.com/tmg_viewitem.asp?itemnbr=552
http://www.myurllink.com/tmg_viewitem.asp?itemnbr=660
http://www.myurllink.com/tmg_viewitem.asp?itemnbr=665

The idea is that when clicked it will change the URL you're currently viewing in your browser. But I'm completely lost as to why the onRelease is running with no mouse interaction at all. Any help or ideas would be greatly appreciated.

Thnx

Medyman
08-27-2008, 04:45 PM
I don't know the technical reasoning here. Something about how the reference is really a variable that calls the function, instead of a call to the function directly. In any case, you can't supply a parameter using the syntax you are.

So, replace t.icon.onRelease = released(url); with:

t.icon.onRelease = function() {
released(url);
}

Of course, url won't be available to the the onRelease function, so you'll have to do something like this:


t.icon.id = i;
t.icon.onRelease = function() {
var url = nodes[0].attributes.urlLoc + nodes[this.id].attributes.itemid;
released(url);
}

Tek81
08-27-2008, 06:55 PM
Thanks for the help, its working now. :)

I'm either very slow at this or whatever, but the only way I could come up with to get the URL i wanted was to do If/If Else statements :(


t.icon.onRelease = function ()
{
if(this == _level0.item1.icon)
{
getURL(nodes[1].attributes.urlLoc, "_self");
}
else if(this == _level0.item2.icon)
{
getURL(nodes[2].attributes.urlLoc, "_self");
}
else if(this == _level0.item3.icon)
{
getURL(nodes[3].attributes.urlLoc, "_self");
}
and so on....

Medyman
08-28-2008, 12:42 AM
I guessed you missed the small edit I made to the url variable.


var url = nodes[0].attributes.urlLoc + nodes[this.id].attributes.itemid;


As long as you include the t.icon.id = i; outside the onRelease function, that will work. Bascially, what this is doing is assigning an arbitrary "id" property to each movieclip that is equal to the index of the for loop. So item0 has an id of 0, item1 has an id of 1, etc...

Then, you can reference that number in the variable to target the XML node you want.