Re: [Flashcoders] 'trace' executes function
On 02/02/2011 10:12, Wenzler, Thomas wrote: Hi List, I just made a little experiment with this code... function setMovieClipX(mc,desiredCoordX):Boolean { var updated:Boolean=true; (desiredCoordX!=mc.x)?mc.x=desiredCoordX:updated=false; "If the x posn isn't the right one move the movieclip, otherwise update the status" return updated; } trace(setMovieClipX(movieClip,286)); ...and found to my utmost surprise that the trace command actually executed the function and updated the movieClip.x position instead of just tracing true or false. It's just doing as you ask, isn't it? If you check omit Trace in the Publish settings, movieClip remains at it's x Position. Well, it would! Wonder if this could be of any use or is a potential danger when using traces to debug? Unless there's something I'm missing, everything is working as I would expect it to. If you pass a function call as a parameter, the function is run. If the function includes code that will move a movieclip, the clip will move. Regards Thomas ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] 'trace' executes function
trace() is a normal function. If you pass arguments to trace(), they will be evaluated first. 1. trace (name == "Jens"); Wouldn't you here expect a true or false depending on your name? 2. Write a custom function to which you pass setMovieClipX(movieClip,286). What parameter type you would use? function testUpdate(updated : Boolean) : void { trace ("updated", updated); } testUpdate(setMovieClipX(movieClip,286)); In this case it seems to be clear that the mc is positioned first. 3. I cannot count how many times I have tried to find a bug due to this trace(expression) issue. While in DEBUG mode everything worked well, the production version did not work :-) It is really a danger that should be in mind. Jens Am 02.02.2011 11:12, schrieb Wenzler, Thomas: Hi List, I just made a little experiment with this code... function setMovieClipX(mc,desiredCoordX):Boolean { var updated:Boolean=true; (desiredCoordX!=mc.x)?mc.x=desiredCoordX:updated=false; return updated; } trace(setMovieClipX(movieClip,286)); ...and found to my utmost surprise that the trace command actually executed the function and updated the movieClip.x position instead of just tracing true or false. If you check omit Trace in the Publish settings, movieClip remains at it's x Position. Wonder if this could be of any use or is a potential danger when using traces to debug? Regards Thomas ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] 'trace' executes function
Hi List, I just made a little experiment with this code... function setMovieClipX(mc,desiredCoordX):Boolean { var updated:Boolean=true; (desiredCoordX!=mc.x)?mc.x=desiredCoordX:updated=false; return updated; } trace(setMovieClipX(movieClip,286)); ...and found to my utmost surprise that the trace command actually executed the function and updated the movieClip.x position instead of just tracing true or false. If you check omit Trace in the Publish settings, movieClip remains at it's x Position. Wonder if this could be of any use or is a potential danger when using traces to debug? Regards Thomas ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders