Solved

changing flash colors based on data in a mysql database

Posted on 2003-10-23
18
166 Views
Last Modified: 2010-04-03
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
Comment
Question by:n1875621
  • 9
  • 8
18 Comments
 
LVL 27

Expert Comment

by:negatyve
Comment Utility
Using Flash 5 or mx?
0
 

Author Comment

by:n1875621
Comment Utility
mx
0
 
LVL 5

Expert Comment

by:Calron
Comment Utility
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
 
LVL 27

Expert Comment

by:negatyve
Comment Utility
//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
 

Author Comment

by:n1875621
Comment Utility
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
 
LVL 27

Expert Comment

by:negatyve
Comment Utility
• 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
 
LVL 27

Expert Comment

by:negatyve
Comment Utility
0
 

Author Comment

by:n1875621
Comment Utility
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
 

Author Comment

by:n1875621
Comment Utility
just got ur url... will try that now

thanks
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 27

Expert Comment

by:negatyve
Comment Utility
You have to attach the code to the frame where the movieclip "mc" lies, not to the movieclip itself..
0
 

Author Comment

by:n1875621
Comment Utility
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
 
LVL 27

Expert Comment

by:negatyve
Comment Utility
// 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
 

Author Comment

by:n1875621
Comment Utility
now nothing comes up when i test the movie...

i added

             this._parent.play();

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

ideas?
0
 
LVL 27

Expert Comment

by:negatyve
Comment Utility
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
 

Author Comment

by:n1875621
Comment Utility
that runs now, but im still getting the black flicker on the first page
0
 

Author Comment

by:n1875621
Comment Utility
sorry, i mean on the first frame
0
 
LVL 27

Accepted Solution

by:
negatyve earned 500 total points
Comment Utility
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
 

Author Comment

by:n1875621
Comment Utility
i think its all working now... i figured some stuff out... thanks very much for your help... works like a charm...
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now