Groups | Blog | Home
all groups > flash actionscript > may 2006 >

flash actionscript : variable listener


LSNsaltlamp
5/13/2006 12:02:07 AM
samdl1
5/13/2006 12:28:00 AM
Perhaps you could try and call the function as the variable changes eg
if it changes with users clicking a button try
my_button.onRelease = my_function() {

but its very difficult to answer your question without being more specific
If you post or pm more info perhaps I can help

Sam
LSNsaltlamp
5/13/2006 1:04:31 AM
I have a function that is dependant on a variable?s value. Basically:
if (variable == 2) {
MyFunction()
}
I need this string to constantly check the value of the variable without
creating and infinite loop.
blemmo
5/13/2006 1:12:50 AM
Check out Object.watch(), it looks for a property of an object and calls a
function when it's changed. If you use this object property instead of a
'normal' variable, you can define a function that gets executed when the
property changes, and has access to the property values. Because MovieClips are
objects too, you could use the playing MC to watch for one of its properties:
this.watch("foo",watchFoo);
function watchFoo(prop, oldVal, newVal){
trace(prop+"-"+oldVal+"-"+newVal);
}
foo = "bar";

The watcher method gets these 3 parameters (name, old and new value of the
property), but can get more. See the Flash Help for a good example.

hth,
blemmo
samdl1
5/13/2006 1:24:11 AM
Ok, I think that you may be looking at this from the wrong way round. Instead
of checking the variable's content indescriminantly try checking the content
specifically when the variable is changed eg if the variable is controlled by a
button

my_btn.onRelease = function() {
if (variable == 2) {
// code
}
};

This should work for any case as the variable has to change via some
interaction (however it is slightly more complicated if the variable is changed
at a keyframe)

If I've still not helped please post how the variable is controlled

Sam

samdl1
5/13/2006 1:28:14 AM
blemmo beat me to the post...his method will of course work (its blemmo!) but
it may overcomplicate the issue if you simply want to discern between two
different options and change the movie based on the choice.

You choose which is most relevent

Sam
AddThis Social Bookmark Button