Skip to main content
charlesn79540358
Inspiring
November 6, 2017
Answered

change symbol background color by code

  • November 6, 2017
  • 3 replies
  • 2782 views

hello,

Is there a way to change symbol background color by code dynamically?

i have it working like this.

function changebackground(hotbutton){

switch (hotbutton){

case "  2":

exportRoot.hotbtn_3.shape_1.graphics.f("#00FFFF").s().p("AhSBTQgjgiAAgxQAAgvAjgjQAigjAwABQAwgBAjAjQAjAjgBAvQABAxgjAiQgjAjgwAAQgwAAgigjg");

exportRoot.hotbtn_2.shape_1.graphics.f("#FF9900").s().p("AhSBTQgjgiAAgxQAAgvAjgjQAigjAwABQAwgBAjAjQAjAjgBAvQABAxgjAiQgjAjgwAAQgwAAgigjg");

exportRoot.hotbtn_2a.shape_1.graphics.f("#FF9900").s().p("AhSBTQgjgiAAgxQAAgvAjgjQAigjAwABQAwgBAjAjQAjAjgBAvQABAxgjAiQgjAjgwAAQgwAAgigjg");

exportRoot.hotbtn_2b.shape_1.graphics.f("#FF9900").s().p("AhSBTQgjgiAAgxQAAgvAjgjQAigjAwABQAwgBAjAjQAjAjgBAvQABAxgjAiQgjAjgwAAQgwAAgigjg");

break;

case "  3":

exportRoot.hotbtn_2.shape_1.graphics.f("#00FFFF").s().p("AhSBTQgjgiAAgxQAAgvAjgjQAigjAwABQAwgBAjAjQAjAjgBAvQABAxgjAiQgjAjgwAAQgwAAgigjg");

exportRoot.hotbtn_2a.shape_1.graphics.f("#00FFFF").s().p("AhSBTQgjgiAAgxQAAgvAjgjQAigjAwABQAwgBAjAjQAjAjgBAvQABAxgjAiQgjAjgwAAQgwAAgigjg");

exportRoot.hotbtn_3.shape_1.graphics.f("#FF9900").s().p("AhSBTQgjgiAAgxQAAgvAjgjQAigjAwABQAwgBAjAjQAjAjgBAvQABAxgjAiQgjAjgwAAQgwAAgigjg");

break;

}

}

but I'm changing the back ground color by doing it hard coded. I don't want to do this for 10-15 symbols.

thanks

    This topic has been closed for replies.
    Correct answer kglad

    can we do that with the button name?

    so instead of hotbtn_2 can we replace that with a string or variable name?

    I'm so sorry maybe I'm not asking the right question I know what I want to do but maybe I'm not asking right.

    thank you


    yes, you can:

    exportRoot['button string'][shape string']

    3 replies

    UDESCO
    Participating Frequently
    November 8, 2017

    Yes, you should be able to access the desired shape inside your symbol and change its fill style.

    Here is a simple example.

    Assuming you have a simple symbol with just a single shape with red color, named mySymbol:

         exportRoot.mySymbol.shape.graphics._fill.style = "#0000FF"; //changes its color to blue.

    charlesn79540358
    Inspiring
    November 8, 2017

    Thank you so much that is what i was looking for

    charlesn79540358
    Inspiring
    November 8, 2017

    the syntax is what kills me the most

    charlesn79540358
    Inspiring
    November 7, 2017

    okay how do you retrieve them?

    Thank you so much for your help.

    kglad
    Community Expert
    Community Expert
    November 7, 2017

    by inspecting the js file in a text editor.

    charlesn79540358
    Inspiring
    November 7, 2017

    I know that but you can't retrieve them by javascript code?

    kglad
    Community Expert
    Community Expert
    November 6, 2017

    what's the logic used to determine which objects to color?

    ie, case 2 colors, 3,2,2a and 2b.  case 3 color 2,2a and 3.  i don't see a logical pattern.

    charlesn79540358
    Inspiring
    November 6, 2017

    so when hotbutton = "   2"

    I'm changing the symbol 3 background back to it's orginal color

    exportRoot.hotbtn_3.shape_1.graphics.f("#00FFFF").s().p("AhSBTQgjgiAAgxQAAgvAjgjQAigjAwABQAwgBAjAjQAjAjgBAvQABAxgjAiQgjAjgwAAQgwAAgigjg");

    then

    I'm changing sumbol 2 background color to an orange color

    exportRoot.hotbtn_2.shape_1.graphics.f("#FF9900").s().p("AhSBTQgjgiAAgxQAAgvAjgjQAigjAwABQAwgBAjAjQAjAjgBAvQABAxgjAiQgjAjgwAAQgwAAgigjg");

    This is the part i don't want to keep hard coding

    exportRoot.buttonname.shape

    is there a way we can use a varaible

    kglad
    Community Expert
    Community Expert
    November 6, 2017

    i don't understand how your response answers my question, but yes, you can use a string in place of shape_1 etc:

    exportRoot.buttonname['shape name']