Shoutbox

[?] Trouble using ImageElmt_SetImageFile() - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [?] Trouble using ImageElmt_SetImageFile() (/showthread.php?tid=83335)

[?] Trouble using ImageElmt_SetImageFile() by Skarbo on 04-22-2008 at 03:02 PM

Hi, i just started scripting scripts for Messenger. Right now im just playing around and figuring out what i can do.

When i try to change the image id=ImgSound2 using ImageElmt_SetImageFile() nothing happens.
Im pretty new at XML, so maybe the problem lies there.

Im running Messenger Plus! Live 4.60.324 on a XP.

Here is an example:

XML

code:
<Interfaces xmlns="urn:msgplus:interface" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:msgplus:interface PlusInterface.xsd">
  <Window Id="WndTest" Version="1">       
    <Attributes>           
      <Caption>Test Window</Caption>
    </Attributes>
    <TitleBar>
        <Title><Text>Hello!</Text></Title>
    </TitleBar>
    <Position ClientWidth="170" ClientHeight="45"/>
    <DialogTmpl/>

    <Elements>
      <Element     xsi:type="ImageElement" Id="ImgSound">
        <Position Top="5" Left="6"/>
        <Image>
          <Name>icon-speaker</Name>
        </Image>
      </Element>
      <Element     xsi:type="ImageElement" Id="ImgSound2">
        <Position Top="5" Left="40"/>
        <Image>
          <Name></Name>
        </Image>
      </Element>
    </Elements>

    <Controls>
        <Control xsi:type="ButtonControl" Id="Test">
            <Position Left="115" Top="25" Width="50"/>               
            <Caption>Test</Caption>
        </Control>
    </Controls>
   
  </Window>
</Interfaces>

JS
code:
function OnEvent_Initialize(MessengerStart)
{
    var Wnd = MsgPlus.CreateWnd("InterfaceTest.xml", "WndTest");
    Wnd.ImageElmt_SetImageFile("ImgSound2","icon-speaker");    // not working
}

function OnEvent_Uninitialize(MessengerExit)
{
}

function OnWndTestEvent_CtrlClicked(Wnd, ControlId)
{
    if(ControlId == "Test")
        Wnd.ImageElmt_SetImageFile("ImgSound2","icon-speaker");    // not working
}
Sorry for the long copy/paste, tried to make it as short and easy as possible.


RE: [?] Trouble using ImageElmt_SetImageFile() by pollolibredegrasa on 04-22-2008 at 03:15 PM

quote:
Originally posted by Skarbo

code:
Wnd.ImageElmt_SetImageFile("ImgSound2","icon-speaker");    // not working


I had this exact problem recently, and found that when using ImageElmt_SetImageFile() with Plus! resource images, you need to prefix the image name with "\\":

code:
Wnd.ImageElmt_SetImageFile("ImgSound2","\\icon-speaker");

Hope this helps :)
RE: [?] Trouble using ImageElmt_SetImageFile() by matty on 04-22-2008 at 05:28 PM

This should be classified as a bug in Plus!. The prepending the backslash is to make the script search for an absolute path not relative to the Scripts folder. However I can see that Plus! searchs the Images folder and if no match is found looks in the resources. It should be implemented that scripts use res:icon-speaker to load a resource. This would help with using resources and absolute paths. In my opinion this is a bug. Anyone agree?


RE: [?] Trouble using ImageElmt_SetImageFile() by Skarbo on 04-22-2008 at 05:51 PM

Thanks, that did the trick.


RE: [?] Trouble using ImageElmt_SetImageFile() by Matti on 04-22-2008 at 06:44 PM

quote:
Originally posted by matty
This should be classified as a bug in Plus!. The prepending the backslash is to make the script search for an absolute path not relative to the Scripts folder. However I can see that Plus! searchs the Images folder and if no match is found looks in the resources. It should be implemented that scripts use res:icon-speaker to load a resource. This would help with using resources and absolute paths. In my opinion this is a bug. Anyone agree?
Yes, it's quite odd that a backslash should be used to load Plus!' own resources... :S
I suggest Plus! should act like this:
  • Check if "icon-speaker" is in the script's Images directory. If it is, use that image file.
  • Else, check if "icon-speaker" is in Plus!' own resources. If it is, use that resource. Else, the function fails and the ImageElement's image is cleared.
Of course, the "res:xxx" option is also possible, but I think it's a bit strange because you'd expect the parameter to look like a normal file path... But it is even worse if you have to place a backslash in front of a resource of Plus! itself, I agree with you there. :)