# How can I use Return In this Case?

**URL:** <https://forum.kirupa.com/t/how-can-i-use-return-in-this-case/113043>\
**Category:** Uncategorized\
**Created:** [June 14, 2004, 2:23pm UTC](https://forum.kirupa.com/t/how-can-i-use-return-in-this-case/113043 "2004-06-14T14:23:08Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![something369](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@something369](https://forum.kirupa.com/u/something369)\
**Post date:** [June 14, 2004, 2:23pm UTC](https://forum.kirupa.com/t/how-can-i-use-return-in-this-case/113043/1 "2004-06-14T14:23:08Z")

</div>

Hello,

Is there a way I can get an array value out of an inline function which in turn is in a function?

Thanx.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 15, 2004, 3:57pm UTC](https://forum.kirupa.com/t/how-can-i-use-return-in-this-case/113043/2 "2004-06-15T15:57:14Z")

</div>

//since you were kind of vague, i coded kind of vague- just tweak to your needs

var myArray:Array

//if calling returns from a diff function  
funtion returnArrayValue(someArray:Array):Object{  
[indent]return someArray[0]  
[/indent]}

function mainFunction(){  
[indent]var someObject:Object

someObject = returnArrayValue(myArray)  
trace(someObject.someProperty)  
[/indent]}  
//  
//if calling from a nested function (like a on the fly handler)-  
var myArray:Array

//obj could also be typed as a movieclip  
funtion returnArrayValue(obj:Object):Object{  
[indent]return object.myArray[0]  
[/indent]}

function createMC(mcRef:String,mcName:String,mcDepth:Number):Boolean{  
[indent]var myMC:MovieClip  
myMC = \_root.createEmptyMovieClip(mcRef,mcName,mcDepth)

//add ref to array  
myMC.myArray = myArray

myMC.onRelease = function(){  
[indent]//modified return to take this object  
trace(this.myOwner.returnArrayValue(this))  
[/indent]}  
[/indent]}  
///////  
again, not sure what youw anted, but figured this might help somehow.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 16, 2004, 11:21am UTC](https://forum.kirupa.com/t/how-can-i-use-return-in-this-case/113043/3 "2004-06-16T11:21:46Z")

</div>

I’m sorry about the ambiguity in my question, but I wasn’t sure how to ask it. Therefore, I developed a simpler version of the question which should let me answer the whole thing.

Can an inline function send out a variable?

ex.

mc.onPress = function(): Void{  
var num:Number = 5;  
};

//How could I get the following trace command to work by bringing out the variable from the function?  
trace(num);

Thank you for the time, and sorry for the confusion… I’m new at actionscript.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 16, 2004, 11:33am UTC](https://forum.kirupa.com/t/how-can-i-use-return-in-this-case/113043/4 "2004-06-16T11:33:42Z")

</div>

Define your variable outside the function

```auto
var num;
mc.onPress = function() {
	num = 5;
};

```

scotty(-:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 16, 2004, 12:05pm UTC](https://forum.kirupa.com/t/how-can-i-use-return-in-this-case/113043/5 "2004-06-16T12:05:32Z")

</div>

actually, you can define your var inside your function-  
mc.onPress = function(): Void{  
var num:Number = 5;  
trace(this.num)  
};

use ‘this’ inside your inline and you should be fine - that was in the second half of my example. this will pull/reference variables local/in the mc you attached the function.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 16, 2004, 12:12pm UTC](https://forum.kirupa.com/t/how-can-i-use-return-in-this-case/113043/6 "2004-06-16T12:12:57Z")

</div>

> [@something369](#):
>
> …Can an inline function send out a variable?..

@defcon, of course you can:) But I thought he wanted to use the variable outside the function…

scotty(-:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 16, 2004, 7:35pm UTC](https://forum.kirupa.com/t/how-can-i-use-return-in-this-case/113043/7 "2004-06-16T19:35:52Z")

</div>

@scotty-hopefully between the two of us he has enough instruction to do anything regarding inline for awhile :).

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 16, 2004, 7:45pm UTC](https://forum.kirupa.com/t/how-can-i-use-return-in-this-case/113043/8 "2004-06-16T19:45:58Z")

</div>

:lol:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 17, 2004, 8:04am UTC](https://forum.kirupa.com/t/how-can-i-use-return-in-this-case/113043/9 "2004-06-17T08:04:29Z")

</div>



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 17, 2004, 8:06am UTC](https://forum.kirupa.com/t/how-can-i-use-return-in-this-case/113043/10 "2004-06-17T08:06:31Z")

</div>

Sorry about the late reply guys. I’ve been busy figuring out all this code and so far most of my major problems have been b/c I neglected what I thought were minor details. Thank you both for the time and help; I appreciate it the detailed explanations.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 17, 2004, 8:51am UTC](https://forum.kirupa.com/t/how-can-i-use-return-in-this-case/113043/11 "2004-06-17T08:51:47Z")

</div>

> [@defcon4](#):
>
> actually, you can define your var inside your function-  
> mc.onPress = function(): Void{  
> var num:Number = 5;  
> trace(this.num)  
> };

Hmmm, I’m not too familiar with this AS 2.0 mumbo jumbo, but if it remained the same as in AS 1.0, that piece of code won’t work. When you put var in front of your declaration, you make that variable local to the function, so (1) you can’t trace it from outside the function, and (2) this.num will return undefined because it doesn’t exist (but num does).

So it’s just a scope issue after all:

```auto
this.mc.onPress = function() {
    this._parent.num += 5;
} ;
this.onEnterFrame = function () {
    trace (this.num) ;
} ;

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 17, 2004, 6:03pm UTC](https://forum.kirupa.com/t/how-can-i-use-return-in-this-case/113043/12 "2004-06-17T18:03:18Z")

</div>

@Ilyas le Pom-  
as1.0 is not the same as as2.0 in terms of syntax. however, you are correct that this.num would work only work in as1.0 in relationship to a component/local variable hence in my example i was setting local to the mc calling the trace. so logically, if it was a parent val, this.num would not work like you said. but in the case of my example, where i declared the num internal, it would. also, in as2.0, declaring external then doing a this.num in the function would still require a ref. to the object holding the num value (like you stated) unless you used listeners/handler objects at which point the var would be relative to the location/declaration of the handler (which could exist anywhere) and not the MC
