Solved

How do you fake a button click. AS3?

Posted on 2009-07-07
8
409 Views
Last Modified: 2013-11-11
say submitBtn.addEventLIstener(MouseEvent.CLICK, doSomething);

function doSomething(ev:MouseEvent):void {
//do stuff.
}

now you want to call doSomething later on in another function. You cant' pass a mousevent cause one doesn't exist.

how do i fake it?
0
Comment
Question by:blue-genie
8 Comments
 
LVL 19

Accepted Solution

by:
moagrius earned 200 total points
Comment Utility

submitBtn.dispatchEvent(new Event("click"));

Open in new window

0
 
LVL 37

Assisted Solution

by:CyanBlue
CyanBlue earned 200 total points
Comment Utility
Or do this???

CyanBlue
submitBtn.addEventLIstener(MouseEvent.CLICK, doSomething);
 

function doSomething(ev:MouseEvent = null):void {

//do stuff.

}
 

doSomething();

Open in new window

0
 
LVL 39

Author Comment

by:blue-genie
Comment Utility
i think the dispatch route is the way i need to go. I just read a post from rascalpants about something related.

CB. calling doSomething() with out passing a paramter throws an incorrect number of arguement error.
0
 
LVL 2

Assisted Solution

by:Iklu
Iklu earned 100 total points
Comment Utility
All those ways work.  Plus one more.
submitBtn.addEventListener(MouseEvent.CLICK, doSomething);

 

function doSomething(e:MouseEvent = null):void

{

	trace("MouseEvent.CLICK");

}

doSomething();                                            //Line 1

doSomething(new MouseEvent(MouseEvent.CLICK));            //Line 2

submitBtn.dispatchEvent(new MouseEvent(MouseEvent.CLICK));//Line 3

//Lines 1, 2 and 3 will call the doSomething function without error.

//Lines 2 and 3 do not require " = null" in the parameter of the doSomething function.

Open in new window

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 39

Author Comment

by:blue-genie
Comment Utility
maybe you guys are doing something i'm not doing, if I call the function without arguments i'm getting errors.
i'm going with the dispatch route.
thanks all
blu.
0
 
LVL 39

Author Closing Comment

by:blue-genie
Comment Utility
:-)
0
 
LVL 37

Expert Comment

by:CyanBlue
Comment Utility
Eh...  You are making sure that you set the default to null for the function argument, right???  I don't see why it throws out the error message...  Hm...

CyanBlue
0
 
LVL 39

Author Comment

by:blue-genie
Comment Utility
whoa CB! you speaking geek.
show me code what you mean by set default to null for function.
i'm having a very blonde day today.

up to an hour ago i thought it was friday. its wednesday.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now