2 Replies Latest reply on Oct 26, 2007 6:03 AM by sjryan_irl

    How do I set the Embed source to a variable

    sjryan_irl
      Hi,
      I want my flex application to create a button where the icon image filename comes from an XML file. I can read the image file name from the XML file and set it to a variable name. The trace confirms that this works. However, I can't seem to get the syntax right for setting the Embed(source=variableName) correct:

      // note the var myXML is already correctly loaded.
      for (var cname:String in ydXML.category) {
      var button:Button = new Button();
      button.label = myXML.category.@name[cname]; // set the button name based on the XML category elements attribute name.
      var imgName:String = myXML.category.@offImage[cname]; // create a string varaible with the image filename to use.
      trace("imgName=" + imgName); // this confirms that the image filename is correct.

      // this next line is the problem, I can't seem to get the syntax correct for this. Is there a way of setting the source to a variable name. I can only find examples showing the source set like: [Embed(source="logo.gif")]. I have also tried: [Embed(source=imgName)] and [Embed(source="{imgName}")] ..

      [Embed(source='{imgName}')]
      var imgCls:Class;

      button.setStyle("icon", imgCls);
      myCanvas.addChild(button);
      }