• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

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?
0
n1875621
Asked:
n1875621
  • 9
  • 8
1 Solution
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
n1875621Author Commented:
i think its all working now... i figured some stuff out... thanks very much for your help... works like a charm...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now