Copy link to clipboard
Copied
hi, i was making this button... the button(my_site_btn) when clicked, goes to a website(URLRequest class)
i want this button enabled only when clicked another button(enable_btn) like toggle button...
i did everything, but the problem is when the button(my_site_btn) is false then also it goes to the link.
this is the code i have been working on(i didn't use any package, i just placed it on timeline)
my code |
---|
import flash.events.MouseEvent; import flash.net.URLRequest; my_site_btn.enabled=false; enable_btn.addEventListener(MouseEvent.CLICK, enable_site); my_site_btn.addEventListener(MouseEvent.CLICK, gotomysite); function enable_site(event:MouseEvent):void { my_site_btn.enabled=!my_site_btn.enabled; } function gotomysite(event:MouseEvent):void { navigateToURL(new URLRequest("http://google.com"), "_blank"); } |
do i have to use if/else conditionals?
and this is my swf file.
thank you.....
use the mouseEnabled property or:
import flash.events.MouseEvent;
import flash.net.URLRequest;
enable_btn.addEventListener(MouseEvent.CLICK, enable_site);
function enable_site(event:MouseEvent):void
{
if(!my_site_btn.hasEventListener(MouseEvent.CLICK){
my_site_btn.addEventListener(MouseEvent.CLICK, gotomysite);
} else {
my_site_btn.removeEventListener(MouseEvent.CLICK, gotomysite);
}
}
function gotomysite(event:MouseEvent):void
{
navigateToURL(new URLRequest("http://google.com"), "_blank");
}
Copy link to clipboard
Copied
use the mouseEnabled property or:
import flash.events.MouseEvent;
import flash.net.URLRequest;
enable_btn.addEventListener(MouseEvent.CLICK, enable_site);
function enable_site(event:MouseEvent):void
{
if(!my_site_btn.hasEventListener(MouseEvent.CLICK){
my_site_btn.addEventListener(MouseEvent.CLICK, gotomysite);
} else {
my_site_btn.removeEventListener(MouseEvent.CLICK, gotomysite);
}
}
function gotomysite(event:MouseEvent):void
{
navigateToURL(new URLRequest("http://google.com"), "_blank");
}
Copy link to clipboard
Copied
thanks, it worked as i expected.
by the way, i was not aware of "hasEventListener"
what does it do?
Copy link to clipboard
Copied
it checks if the object has an event listener of the type specified in the method's argument.
Copy link to clipboard
Copied
thanks, i will use it from now on
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now