PDA

View Full Version : javascript layer visibility in flash


synefx
07-19-2007, 09:58 PM
i have a swf that holds several icons called through an xml doc. each icon has a button that unhides a div layer in an html document the swf is loaded into.

my problem is this:
my button uses a global javascript function to unhide the div layer - but i need to unhide a unique layer for each icon. changing the code for the button is not really an option - it has to stay like this:

urlBtn.onRelease = function()
{
getURL("javascript:openmylayer()");
}

what would be the best way to do this?

thanks for any help! :)

spriggan
07-23-2007, 01:54 AM
You can't change it at all or you don't know how to?

Because the only way to stay global like that and have the functionality you want would be to pass a variable into the function to tell it which layer to hide. so this, where this.divName is a different ID assigned to each instance of your button(s):


urlBtn.onRelease = function()
{
getURL("javascriptpenmylayer(this.divName)");
}



Then your JavaScript would look something like this:


function javascriptpenmylayer(divName){
if(document.getElementById(divName).style.visibili ty!='visible'){
document.getElementById(divName).style.visibility= 'visible'
}else{
document.getElementById(divName).style.visibility= 'hidden'
}
}


pretty simple, but you have to have a way to pass the Div tag id (ie the layer) from flash to the Javascript.