Solved

changing flash colors based on data in a mysql database

Posted on 2003-10-23
18
167 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
ID: 9607949
Using Flash 5 or mx?
0
 

Author Comment

by:n1875621
ID: 9608009
mx
0
 
LVL 5

Expert Comment

by:Calron
ID: 9608094
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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 27

Expert Comment

by:negatyve
ID: 9608184
//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
ID: 9608342
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
ID: 9608372
• 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
ID: 9608393
0
 

Author Comment

by:n1875621
ID: 9608442
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
ID: 9608459
just got ur url... will try that now

thanks
0
 
LVL 27

Expert Comment

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

Author Comment

by:n1875621
ID: 9608493
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
ID: 9608537
// 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
ID: 9608591
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
ID: 9608620
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
ID: 9608775
that runs now, but im still getting the black flicker on the first page
0
 

Author Comment

by:n1875621
ID: 9608777
sorry, i mean on the first frame
0
 
LVL 27

Accepted Solution

by:
negatyve earned 500 total points
ID: 9608853
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
ID: 9608860
i think its all working now... i figured some stuff out... thanks very much for your help... works like a charm...
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
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…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
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.

770 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