Hello,
Is there a way I can get an array value out of an inline function which in turn is in a function?
Thanx.
Hello,
Is there a way I can get an array value out of an inline function which in turn is in a function?
Thanx.
//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.
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.
Define your variable outside the function
var num;
mc.onPress = function() {
num = 5;
};
scotty(-:
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.
@defcon, of course you can:) But I thought he wanted to use the variable outside the function…
scotty(-:
@scotty-hopefully between the two of us he has enough instruction to do anything regarding inline for awhile :).
:lol:
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.
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:
this.mc.onPress = function() {
this._parent.num += 5;
} ;
this.onEnterFrame = function () {
trace (this.num) ;
} ;
@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
:: Copyright KIRUPA 2024 //--