dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: movie clip change color from external txt!

  1. #1
    Member
    Join Date
    Jul 2001
    Posts
    58
    I need to do this..I want a mc change his color...i want the target color is loaded from an external txt file by loading variables...is it possible..and which could be the right actionscript syntax???
    thx

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    If you want a fast change use setRGB if you want a slow change use object.setTransform. For syntax read about both methods in your actionscript reference. Then choose which one is appropriate.
    gparis

  3. #3
    Member
    Join Date
    Jul 2001
    Posts
    58

    maybe i don't explain what i need..

    i know how to change color to a MovieClip..the problem is to have the exadecimal value in an external txt file..try to do this...flash doesn't recognize the value and set the object to black...this is what i tried:

    loadVariables ("new.txt", "");
    mycolor = new Color("a");
    mycolor.setRGB(value);

    where new.txt is:

    value=0x33cc00

    and "a" is the instance name of the clip i want to change color...
    very very weird....

    if i setup a variable called value and assign the exadecimal value inside the flash movie it works fine,but if i load the variable "value" from an external txt file (new.txt) the "a" movie clip turns to black...

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    maybe you could try and use parseInt(value) instead.
    And use the data clip event with the color change:

    onClipEvent (load) {
    loadVariables ("new.txt", "");
    }
    onClipEvent (data) {
    mycolor = new Color(this);
    mycolor.setRGB(parseInt(value));
    }

    I used this because i put that script on the clip which color is supposed to change. If elsewhere use absolute path: _level0.a
    gparis

  5. #5
    Sleepy
    Join Date
    Apr 2001
    Location
    Tallahassee, FL
    Posts
    498
    why not make the value in your text file look like:
    value=33cc00;

    then in your flash do something like (ignore the numbers):

    1)loadVariables("new.txt","");
    2)mycolor = new Color("a");
    3)
    4)//convert string to hex
    5)var valAsHex = parseInt(value, 16);
    6)
    7)//set color
    8)mycolor.setRGB(valAsHex);

    //-------------------------
    alternatively, you could also try this line of code instead for line #5:

    var valAsHex = parseInt("0x" + value);


    If that doesn't work for you the problem is that your value is a STRING, when setRGB is looking for a HEX number...I can work up an example if you need me to

    HTH
    [Edited by Gary022576 on 02-19-2002 at 02:59 PM]

  6. #6
    Member
    Join Date
    Jul 2001
    Posts
    58

    thx

    thx a lot gparis and Gary022576...this solution works perfectly! i used on clipevent handler..thx gparis...

  7. #7
    Junior Member
    Join Date
    Mar 2000
    Posts
    20
    Tnx alot!

    i had a .xml with something like: <color="ff6600"/> and got realy crazy about to put it where it should change som' color...

    this-> var valAsHex = parseInt("0x" + value);

    was the thing i missed...

    Robert.

  8. #8
    Sleepy
    Join Date
    Apr 2001
    Location
    Tallahassee, FL
    Posts
    498
    excellent!

    good luck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center