ActionScript call a function within another function - actionscript-3

I have a function (gofromTheFuture) that controls tweening objects that is then linked to various buttons, however I also want it to be called from this function below, but flash gives me this error:
Incorrect number of arguments. Expected 1.
function exitHandler(event:Event):void
{
event.preventDefault();
gofromTheFuture();
}
function gofromTheFuture(evt:Event):void{
myTimeline2.insertMultiple( TweenMax.allTo([TheFutureArtwork, pausebutton, playbutton, Verse, Chorus, Verseto1, Verseto2, Chorusto1, Chorusto2, rewind, fastforward, progressline, progressbar, TheFutureComments],
0.25, {x:"450", autoAlpha:0, onComplete:exitAnimation}) );
}
function exitAnimation():void {
trace("Return to main menu.");
gotoAndStop(1, "Menu");
}
How do I call this gofromTheFuture from within this function?
Thanks

Try change gofromTheFuture() to:
function gofromTheFuture(evt:Event = null):void

Related

Calling a function in Actionscript 3

I am trying to call a function using the function name and (); That is how I have done it in the past and how it is shown in examples on different sites. I get an error saying it is expecting 1 argument. Does calling a function require an argument?
Hi i have gone through your question you have said about calling function needed any argument here no needed they error says expecting 1 argument means you want to pass the event name in the function here in this example i have shown..
//creating event listener for card movieclip
card_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag);
//In this function im passing the event name done (e:MouseEvent) likewise you want to do in the function then error will clear..
function drag(e:MouseEvent):void
{
var mc:MovieClip = MovieClip(e.currentTarget);
trace(mc.name);
mc.startDrag();
}
Thank You ...

Event does not happend on moving symbol in Animate CC (HTMLCanvas)

Hi this code is working well on moving symbol(classic tween)
var frequency = 3;
stage.enableMouseOver(frequency);
this.movieClip_1.addEventListener("mouseover", fl_MouseOverHandler_9);
function fl_MouseOverHandler_9()
{
alert("Moused over");
// this.gotoAndStop(41);
}
but if i replaced with this.gotoAndStop(41); it does not work
the event-target is accessible (will be passed within the event-handler-parameter-object) like this:
this.movieClip_1.addEventListener("mouseover", fl_MouseOverHandler_9);
then in the handler function:
function fl_MouseOverHandler_9(evt)
{
// "evt.currentTarget" represents the event-trigger
evt.currentTarget.gotoAndStop(41);
}
or you can pass the scope of the desired MC to the event handler:
this.movieClip_1.addEventListener("mouseover", fl_MouseOverHandler_9.bind(this.movieClip_1));
then in the handler function:
function fl_MouseOverHandler_9(evt)
{
// "evt.currentTarget" still represents the event-trigger
// evt.currentTarget.gotoAndStop(41);
//but now you can access the referenced scope with "this"
this.gotoAndStop(41);
}
cheers
mike

AS3/Flash: Calling a function MouseEvent from a datagrid click

I'm calling a function by clicking a button:
searchBT.addEventListener(MouseEvent.CLICK,searchXML);
function searchXML(Event:MouseEvent)
I want to call the same function from a datagrid.
Right now, when clicking on the datagrid several dynamic text fields are filled with the data of the clicked row.
I nead to perform the function (searchXML) at the same time. This and other calls result in errors:
fullList.dataGrid.addEventListener(ListEvent.ITEM_CLICK, clickGrid);
function clickGrid(e:ListEvent):void
{
searchXML(Event);
...
}
Any idea?
Cheers.
It is because the searchXML method waits for argument of MouseEvent type. You can redefine this method like this:
function searchXML(Event:MouseEvent = null)
And call it simple:
function clickGrid(e:ListEvent):void
{
searchXML();
// ...
}

AS3: Clicking a button via actionscript

This is my very simple code:
g2.addEventListener(MouseEvent.CLICK, buttG2);
function buttG2(event:MouseEvent):void
{
buttonNote="G2";
addWholeNote();
}
It works great when I click the button, but is it possible to fire this function from another function using Actionscript?
In some other function:
function otherFunction() {
buttG2(null);
}
You pass in null since it is never used. You could also give the parameter a default value like this:
function buttG2(event:MouseEvent = null):void
{
buttonNote="G2";
addWholeNote();
}
And then call the function without any parameters as event will then be null as per default:
function otherFunction() {
buttG2();
}
Use a default parameter of null to allow the function call from elsewhere in your code. You won't be able to get any mouseevent data, but that's probably not an issue. You could pass null into your function as you have it, but I find this to be cleaner.
g2.addEventListener(MouseEvent.CLICK, buttG2);
function buttG2(event:MouseEvent = null):void
{
buttonNote="G2";
addWholeNote();
}
call it like any other function, the param is now optional.
buttG2();

Passing e:MouseEvent as an argument via setInterval

So i have this function
capture_mc.buttonMode = true;
capture_mc.addEventListener(MouseEvent.CLICK,captureImage);
function captureImage(e:MouseEvent):void {
//lalalala
}
I want to call this function every 2 seconds (after mouse click event happens).
I tried using setInterval
setInterval(captureImage,2000,e:MouseEvent);
but it leads to following error
1084: Syntax error: expecting rightparen before colon.
What's wrong ?
And ya, i am new to AS.
First, since this is AS3 you should be using Timer and TimerEvent. I'll show you how in the example.
Now you'll need to separate your functions:
edit: I've updated this to be safer based on #(Juan Pablo Califano) suggestions. I would keep the same timer for ever if the amount of time isn't going to change.
// first param is milliseconds, second is repeat count (with 0 for infinite)
private var captureTimer:Timer = new Timer(2000, 0);
captureTimer.addEventListener(TimerEvent.TIMER, handleInterval);
function handleClick(event:MouseEvent):void
{
// call here if you want the first capture to happen immediately
captureImage();
// start it
captureTimer.start();
}
function handleInterval(event:TimerEvent):void
{
captureImage();
}
function captureImage():void
{
// lalalala
}
You can also stop the timer with captureTimer.stop() whenever you want.
The problem is that you should use the parameterName:ParameterType syntax only when declaring formal parameters (or when declaring vars and consts). Meaning, this is valid only when you are defining a function:
function func(paramName:Type){
}
When you call the function, you don't have to put the type of the arguments.
So, your function call should look like this:
setInterval(captureImage,2000,e);