Link to home
Start Free TrialLog in
Avatar of chadsaun
chadsaun

asked on

Passing a variable

I am using Flash 7.0. I am passing a variable (a hex color) to the flash movie. When I pass this variable I want the object's color to change. I can get this working if I have a button in the movie because then I can use a rollOver event to or release to update the color. My problem is that I don't want a button in the flash movie. I just want to pass the variable, and when the variable changes to update the color of the object.

Is there some kind of way to listen to the variable that is being passed in and see if it changes, and if it does to update the color?
Avatar of FLAASHER
FLAASHER
Flag of Saudi Arabia image

dont use  rollOver event to or release
u can use onLoad event for ur movieclip to do it


FLAASHER
Avatar of chadsaun
chadsaun

ASKER

I just added an actionscript in the second frame telling it to go back to frame 1 if the variable wasn't empty. It works now.
good news
Avatar of Aneesh Chopra
yes, it is possible

you should add a watch on the variable you want to listen on......

example code here:
--------------------
//this is the variable which receives the color value..
var ColorVar;

//add watch on it.. below we have attached a function to it, as it received new value...
//this function will run automatically
_root.watch("ColorVar", messageReceived);


messageReceived = function (prop, oldVal, newVal)
{
      changeColor(newVal);
      return newVal;
};


//function to change color
changeColor = function (newColor)
{
      //code to change color
};
------------------

I hope all would be clear.
I will try that out. We are further developing this flash movie and we might need to do something like that. That way looks a lot better anyway than we do it now.

A couple questions on that code though:

The messageReceived function has three parameters. In the line _root.watch you don't pass any parameters with that function. Do they default to something automatically? Also, what is the 'prop' parameter?
ASKER CERTIFIED SOLUTION
Avatar of Aneesh Chopra
Aneesh Chopra
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great thank you. That clears up all my questions. I'll try to get to this within a few days and report back.
welcome..

wait for your confirmation