# Passing a value to a function while calling thru addEventListener

**URL:** <https://forum.kirupa.com/t/passing-a-value-to-a-function-while-calling-thru-addeventlistener/309034>\
**Category:** flash\
**Created:** [May 5, 2010, 11:16am UTC](https://forum.kirupa.com/t/passing-a-value-to-a-function-while-calling-thru-addeventlistener/309034 "2010-05-05T11:16:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![karthic\_vkn](https://avatars.discourse-cdn.com/v4/letter/k/da6949/32.png) [@karthic\_vkn](https://forum.kirupa.com/u/karthic_vkn)\
**Post date:** [May 5, 2010, 11:16am UTC](https://forum.kirupa.com/t/passing-a-value-to-a-function-while-calling-thru-addeventlistener/309034/1 "2010-05-05T11:16:51Z")

</div>

Hi All,

How to pass a value to a function while its calling thru ‘Montion\_change’ or ‘Motion\_Finish’ or …

here I try to pass a value to “tweenEvent function” while that function called… i m using a private variable inside ‘mainfunction’ (dont tell create that variable out the function ![](http://forum.kirupa.com/uploads/kirupa/5541/fb5b90eb3225b77d.gif) ), i just assigning a string value to that variable. after this, i m starting a tween and when the tween started calling ‘tweenFunction’ using addEventListener,

Inside ‘tweenFunction’ function, i try to trace the ‘Name’ variable which is inside the mainfunction… not working !!!

Here my code…

* * *

import fl.transitions._;  
import fl.transitions.easing._;

function mainFunction() {  
var Name:String;  
var MC:MovieClip=drawCircle();  
MC.x=MC.y=100;  
addChild(MC);  
Name=“karthic”;  
var newTween:Tween=new Tween(MC,“x”,Strong.easeOut,100,500,5,true);  
newTween.addEventListener(TweenEvent.MOTION\_CHANGE, tweenFunction(Name));  
}

mainFunction();

function tweenFunction(evt:TweenEvent, Name):void {  
trace(Name);  
}

function drawCircle() {  
var circle:MovieClip=new MovieClip();  
circle.graphics.beginFill(0xFF0000);  
circle.graphics.drawCircle(0,0,20);  
return (circle);  
}
