Solved

changing flash colors based on data in a mysql database

Posted on 2003-10-23
18
172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

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.

Question has a verified solution.

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

Suggested Solutions

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

749 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