Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to solve this problem?

Community Beginner ,
Feb 17, 2014 Feb 17, 2014

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

TOPICS
ActionScript
607
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 17, 2014 Feb 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");

}

Translate
Community Expert ,
Feb 17, 2014 Feb 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");

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 17, 2014 Feb 17, 2014

thanks, it worked as i expected.

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

what does it do?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 18, 2014 Feb 18, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 18, 2014 Feb 18, 2014

thanks, i will use it from now on

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 19, 2014 Feb 19, 2014
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines