Skip to main content
Participant
February 17, 2014
Answered

How to solve this problem?

  • February 17, 2014
  • 1 reply
  • 668 views

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.....

This topic has been closed for replies.
Correct answer kglad

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");

}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
February 17, 2014

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");

}

Participant
February 18, 2014

thanks, it worked as i expected.

by the way, i was not aware of "hasEventListener"

what does it do?

kglad
Community Expert
Community Expert
February 18, 2014

it checks if the object has an event listener of the type specified in the method's argument.