| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Defender of Obviousness
Join Date: Dec 2003
Posts: 21
|
hi,
is there a way to pass the reference of a variable(a) into a function so that when a's value is changed in the function, the actual variable value is changed and not only the a in the function? i have this code snippet below => ActionScript Code:
the variable "logoFaded" that's declared and initialised on frame 1 is being passed into alphaFaded() by value currently and only the variable "flag" is set to true. i tried to attach a variable to logoFadeListener like this but it didnt work as well ActionScript Code:
|
|
|
|
|
|
#2 |
|
Registered User
|
Flash always passes primitives by value, so the solution is to put it into an object.
This is what you tried to do whit the last attempt, but when you pass logoFadeListner.logoFaded to the function your parsing a Boolean value (primitive). If it is to work you have to pars just logoFaderListner and then within your function ask for the variable. ActionScript Code:
By the way the variables parsed to the function “alphaFaded” are not within the scope of the onEnterFrame function of the Logo_mc. |
|
|
|
|
|
|
|
|
#3 |
|
Defender of Obviousness
Join Date: Dec 2003
Posts: 21
|
hi Crismo,
thanks for the heads up! it worked after i wrapped logoFaded into an object and passed the object into the function but 1 thing is, u mentioned that the alphaFade parameters are not scoped to the onEnterFrame handler, i tried to test that out with a trace of 2 parameters in the event handler and the values were correct... |
|
|
|
|
|
#4 | |
|
Defender of Obviousness
Join Date: Dec 2003
Posts: 21
|
Quote:
i think i misunderstood u when u said that the function parameters were not scoped to the onEnterFrame handler. Did u mean that the parameters will not be unique to the event handler? |
|
|
|
|
|
|
#5 |
|
Registered User
|
Nah just my old OOP lessons that are interfering with the ”whimsical magical” ways of actionscripting.
Looking at it from a purly OO angle, the moviclip function should not be able to see the variables parsed to the alphaFaded function. But then this is what I love about Actionscript, the possibility to cheat when your in a hurry .I have given an example of the problem that bugs me with this kind of solution. If actionscript had been consistent, the 2 functions should both have been able to access the parsed variables, but they are not. It could of course bee some feature of anonymous inner classes / functions etc. But since I don’t know for sure, I’m just going to write it up as a practical feature of actionscript It’s really not that important as long as we can choose our self to be consistent or not. ActionScript Code:
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|