Today i got asked to add links to a flash animation that i have done recently. The flash animation in question has dynamic title’s and content based on two movie clips, which are built from an array of data pulled in from XML.
Knowing i needed to add a “getUrl()” function and “onRelease” event handler for the dynamic movie clips, I thought to myself “what would be the easiest was to do this…”
With the clips being made inside a simple for loop, i hoped the data being pulled from the array would be retained and correct for when the event handler was eventually triggered (optimistic i know!). If you hadn’t already guessed this didn’t work, so off i went thinking how i can have the right data when the event handler fires.
After a little while and tinkering with my code i finally figured out a solution. When attaching the movieClip you can store the instance in a variable and then set a variable inside the movie clip. When the event handler is triggered it simply calls “this.linkTo” (”this”, referring to the movieClip, and “linkTo” refferring to the variable) as the getURL() address parameter
The code snippet for this is:
// Create new instance of the Section_Title movie clip
var SectionTitle = attachMovie("Section_Title", Sections[ii][0], ii, { _x:-230, _y:_yPos });
// Set a variable for this movie clip for the navigate link
SectionTitle.linkTo = Sections[ii][2];
// Create event handler for the click release
SectionTitle.onRelease = function(){
// Goto page save in thje movie clip linkTo variable
getURL(this.linkTo);
}