Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do you fake a button click. AS3?

Posted on 2009-07-07
8
Medium Priority
?
423 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 19

Accepted Solution

by:
moagrius earned 800 total points
ID: 24794025

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

Open in new window

0
 
LVL 37

Assisted Solution

by:CyanBlue
CyanBlue earned 800 total points
ID: 24794173
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
ID: 24801150
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Assisted Solution

by:Iklu
Iklu earned 400 total points
ID: 24801347
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
 
LVL 39

Author Comment

by:blue-genie
ID: 24802118
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
ID: 31600543
:-)
0
 
LVL 37

Expert Comment

by:CyanBlue
ID: 24802451
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
ID: 24803264
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…

610 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