changing flash colors based on data in a mysql database

I need a simply routine that will change an object in flash to a different color depending on on the value in the database....

lets say

value : color
1   green
2   blue
3   red

i basically need the full example of the flash action script... (i can pull it from the database - but i dont know how to pass it to flash)

does this make sense?
n1875621Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

negatyveCommented:
Using Flash 5 or mx?
0
n1875621Author Commented:
mx
0
CalronCommented:
Your php side will look somethign like this:

get data from db

   
     $color= "&color=" . value from db. "&";

    echo $color;
     

Then in flash you will have to have something like the following:

var loader1 = new LoadVars();
loader1.onLoad = function() {
  // in here we now should have 1 variable colro
  color = Number(color);
  var myCol = new Color(myovieClip);
  switch (color) {
    case 1: myCol.setRGB(0xFF0000);
       break;
   case 2: myCol.setRGB(0x00FF00);
       break;
  }
}
loader1.load("myphpscript.php");
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

negatyveCommented:
//ok. suppose you've got the "mc" movieclip on the stage: add this script to the frame where "mc" lies:

data_var = new LoadVars();
data_var.path = this;
data_var.onLoad = function(success)
{
      if(success){
            this.path.mc.col = new Color(this.path.mc);
            switch(this.loadedColor)
            {
                  case "green":
                        var value = 0x009900;      break;
                  case "blue":
                        var value = 0x003399;      break;
                  case "red":
                        var value = 0xFF0000;      break;
            }
            this.path.mc.col.setRGB(value);
      } else {
            trace("PAGE NOT FOUND");
      }
};
data_var.load("page.php");
// data_var.load("page.asp");
// data_var.load("page.cfm");



your php page should return the color this way:

echo "loadedColor=".$colorfromdb."&"

your asp page should return the color this way:

Response.write("loadedColor=" & request("colorfromdb") & "&")

your cfm page should return the color this way:

<cfoutput>"loadedColor="&#colorfromdb#&"&"</cfoutput>
0
n1875621Author Commented:
I understand the source code you've all written... but where to put it is part of the problem also....

I have uploaded a simple flash file for an example, its a simple square fading in and out moving across the screen and can be downloaded from http://www.johnnyville.com/johnnyville/test.fla

where would I put the code for this to test....??
0
negatyveCommented:
• edit your "square" movieclip in the library
• select the rectangular shape
• press F8 and convert it to mc
• open properties panel, and give it the instance name "mc"
• drop the code in the same frame where the moviecli lies (movieclip "mc" inside "square")
0
negatyveCommented:
0
n1875621Author Commented:
negatyve,

Im getting these errors in the output

Scene=Scene 1, Layer=Layer 2, Frame=1: Line 1: Statement must appear within on/onClipEvent handler
     data_var = new LoadVars();

Scene=Scene 1, Layer=Layer 2, Frame=1: Line 2: Statement must appear within on/onClipEvent handler
     data_var.path = this;

Scene=Scene 1, Layer=Layer 2, Frame=1: Line 3: Statement must appear within on/onClipEvent handler
     data_var.onLoad = function(success)

Scene=Scene 1, Layer=Layer 2, Frame=1: Line 21: Statement must appear within on/onClipEvent handler
     data_var.load("flash.php");

0
n1875621Author Commented:
just got ur url... will try that now

thanks
0
negatyveCommented:
You have to attach the code to the frame where the movieclip "mc" lies, not to the movieclip itself..
0
n1875621Author Commented:
it seems to be working now except it does something quite ugly and that is it displays the black box in the first frame and then changes it to green or whatever so that is very undesirable... is there a way around that? like maybe loading the color before the script displays so it starts off in the desired color?
0
negatyveCommented:
// stop the main timeline
this._parent.stop();
// set the movieclip visibility to false
this.mc._visible = false;

data_var = new LoadVars();
data_var.path = this;
data_var.onLoad = function(success)
{
    if(success){
         this.path.mc.col = new Color(this.path.mc);
         switch(this.loadedColor)
         {
              case "green":
                   var value = 0x009900;     break;
              case "blue":
                   var value = 0x003399;     break;
              case "red":
                   var value = 0xFF0000;     break;
         }
         this.path.mc.col.setRGB(value);
         // set the movieclip visibility back to true;
         this.path.mc.col._visible = true;
    } else {
         trace("PAGE NOT FOUND");
    }
};
data_var.load("page.php");
0
n1875621Author Commented:
now nothing comes up when i test the movie...

i added

             this._parent.play();

under where you make mc.col._visible = true....

ideas?
0
negatyveCommented:
sorry, corrected script:

// stop the main timeline
this._parent.stop();
// set the movieclip visibility to false
this.mc._visible = false;

data_var = new LoadVars();
data_var.path = this;
data_var.onLoad = function(success)
{
    if(success){
         this.path.mc.col = new Color(this.path.mc);
         switch(this.loadedColor)
         {
              case "green":
                   var value = 0x009900;     break;
              case "blue":
                   var value = 0x003399;     break;
              case "red":
                   var value = 0xFF0000;     break;
         }
         this.path.mc.col.setRGB(value);
         // set the movieclip visibility back to true;
         this.path.mc._visible = true;
         this.path._parent.play();
    } else {
         trace("PAGE NOT FOUND");
    }
};
data_var.load("page.php");
0
n1875621Author Commented:
that runs now, but im still getting the black flicker on the first page
0
n1875621Author Commented:
sorry, i mean on the first frame
0
negatyveCommented:
You can try it this way. Leave on the frame:

// stop the main timeline
this._parent.stop();
data_var = new LoadVars();
data_var.path = this;
data_var.onLoad = function(success)
{
      if (success) {
            this.path.mc.col = new Color(this.path.mc);
            switch (this.loadedColor)
            {
                  case "green" :
                        var value = 0x009900;
                        break;
                  case "blue" :
                        var value = 0x003399;
                        break;
                  case "red" :
                        var value = 0xFF0000;
                        break;
            }
            this.path.mc.col.setRGB(value);
            // set the movieclip visibility back to true;
            this.path.mc._visible = true;
            this.path._parent.play();
      } else {
            trace("PAGE NOT FOUND");
      }
};

And assign to the movieclip "mc":

onClipEvent(load){
      this._visible = false;
      this._parent.data_var.load("page.php");
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
n1875621Author Commented:
i think its all working now... i figured some stuff out... thanks very much for your help... works like a charm...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.