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!

Callback Functions: Taking a Variable Literally

Status
Not open for further replies.

BooYaKaSha

Technical User
May 18, 2002
62
0
0
US
Long story short, I have this script:

for (i = 1; i <= currentType.length; i++)
// (sic)
{
this[&quot;piece&quot; + i].onRollOver = function()
{
getDescription(i);
descriptionBar.gotoAndPlay(&quot;over&quot;);
}
// (sic)
}

The &quot;getDescription(i)&quot; part won't work, and I understand why, but how can I modify that to make it work. I need &quot;i&quot;'s value to be taken literally right then and there, not when the callback gets executed.

I've tried things like &quot;eval(i)&quot;, &quot;function() {return i}&quot; and &quot;i.toString()&quot; to no avail.
Thanks a million for your help.
 
what does the function getDescription look like



_______________________________________
You know you're old if you can remember when bacon, eggs and sunshine were good for you
 
function getDescription(whichPiece)
{
descriptionBar.slider.title = currentType[whichPiece].title;
descriptionBar.slider.subtitle = currentType[whichPiece].subtitle;
descriptionBar.slider.summary = currentType[whichPiece].summary;
descriptionBar.slider.description = currentType[whichPiece].description;
}

currentType is a reference to an object that was parsed from an XML file.

I figured out one solution:
getDescription(this._name.substr(this._name.length - 1, 1));

But if you know of a more elegant solution I'm definitely all ears. Thanks

 
untested but given your solution im sure this will work

for (i = 1; i <= currentType.length; i++)
// (sic)
{
this[&quot;piece&quot; + i].onRollOver = function()
{
getDescription();
descriptionBar.gotoAndPlay(&quot;over&quot;);
}
// (sic)
}


_______________________________________
You know you're old if you can remember when bacon, eggs and sunshine were good for you
 
Are you sure that's right?

I need to pass getDescription() a number.
 
yes im sure but as i said i aint tested it





_______________________________________
You know you're old if you can remember when bacon, eggs and sunshine were good for you
 
I think the problem with Bill's code is that there was an 'i' in square brackets in there and the site has treated it as an 'italics' tag. Can you repost Bill with the code inside
Code:
tags?
 
Hmmm.. the site also parses 'code' tags of course...

That should have read:

the code inside '[''code' ']' tags?
 
well spotted wangbar thats exactly what i had

(square baracket i sqr.brk)

_______________________________________
You know you're old if you can remember when bacon, eggs and sunshine were good for you
 
OH, sorry Bill, was wondering why half of it was in italics

To make sure I am trying the right thing:

for (i = 1; i <= currentType.length; i++)
// (sic)
{
this[&quot;piece&quot; + i].onRollOver = function()
{
getDescription();
descriptionBar.gotoAndPlay(&quot;over&quot;);
}
// (sic)
}

I tried the above and unfortunately it did not work.
 
thats what i expected to work

well at least you have your original solution

_______________________________________
You know you're old if you can remember when bacon, eggs and sunshine were good for you
 
Maybe Bill will someday learn how to use &quot;code&quot; tags here on TT!
Read the last note in &quot;Process TGML&quot; on the bottom of the post window... If you can find it!

Regards,

cubalibre2.gif

Bacon, eggs and sunshine are still good for me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top