Loading a external image |
Author: |
Message: |
Yorick
Junior Member
Posts: 22
34 / /
Joined: Mar 2007
|
O.P. Loading a external image
Hello,
While I was working on my Last.fm for Messenger Plus! Live I realized that I wasn't able to display an image from an internet location in a window. Maybe it's possible, but I don't know how... anyone?
Thanks in advance,
Yorick
|
|
03-01-2007 05:00 PM |
|
|
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
Joined: Apr 2004
|
RE: Loading a external image
First you should download the file to a temporany location, which you can do with the new MsgPlus.DownloadFile function. Then, you can use PlusWnd.ImageElmt_SetImageFile to change the image displayed. Don't forget to delete your file afterwards!
|
|
03-01-2007 05:24 PM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
Joined: Dec 2002
Status: Away
|
RE: Loading a external image
quote: Originally posted by Mattike
First you should download the file to a temporany location, which you can do with the new MsgPlus.DownloadFile function. Then, you can use PlusWnd.ImageElmt_SetImageFile to change the image displayed. Don't forget to delete your file afterwards!
However when you are setting the Image from a location that is not in your Scripts folder you need to prefix the path with a \.
For instance if you saved your image to C:\Temp and it was called myimage.jpg the code would be:
code: pPlusWnd.ImgElmt_SetImageFile('myimage', '\\C:\\Temp\\myimage.jpg');
|
|
03-01-2007 06:03 PM |
|
|
Yorick
Junior Member
Posts: 22
34 / /
Joined: Mar 2007
|
O.P. RE: Loading a external image
Thanks a lot guys!
Almost worked it out now, but I still have a bit of a problem.
I have the following code:
code: WndProfileInformation = MsgPlus.CreateWnd('WndProfileInformation.xml', 'WndProfileInformation');
if(MsgPlus.DownloadFile(avatar))
{
Debug.Trace('[Download] Started');
}
else
{
Debug.Trace('[Download] Failed');
}
And then you have to use the OnEvent_DownloadFileComplete(), but how do I append the image to the above made window? How can I get the WndProfileInformation window in the OnEvent_DownloadFileComplete function?
code: function OnEvent_DownloadFileComplete(Url, OutFile, Success)
{
if(Succes)
{
WndProfileInformation.ImgElmt_SetImageFile('ImgDisplayPic', OutFile);
var File = new ActiveXObject("Scripting.FileSystemObject");
File.DeleteFile(OutFile);
}
}
This post was edited on 03-02-2007 at 06:54 PM by Yorick.
|
|
03-02-2007 06:53 PM |
|
|
CookieRevised
Elite Member
Posts: 15517 Reputation: 173
– / /
Joined: Jul 2003
Status: Away
|
RE: Loading a external image
Each and every variable in a script needs to be declared somewhere. This is done using the var statement.
eg: code: var MyVar = "Hello World";
If you declare a variable inside a function, it is a local variable. The variable will only exist as long as the function runs. When the function ends, the variable will not exist anymore.
eg: code: function DoSomething() {
var MyLocalVar = "Hello World"
}
If you declare a variable in the main scope of the script, thus outside any functions, it is a global variable. The variable will exist as long as the script is running and thus can be used from anywhere in the script, including from inside funtcions...
eg: code: var MyGlobalVar = "Hello World"
function DoSomething() {
//blahblah
}
Short answer: declare WndProfileInformation as a global variable.
This post was edited on 03-02-2007 at 07:03 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
|
|
03-02-2007 07:01 PM |
|
|
Yorick
Junior Member
Posts: 22
34 / /
Joined: Mar 2007
|
O.P. RE: Loading a external image
At the top of the script I have
code: var WndProfileInformation;
Is this not enough? So in the function I only use
code: WndProfileInformation.ImgElmt_SetImageFile('ImgDisplayPic', OutFile);
But for some reason I can't use it in the download function...
EDIT: Made a mistake in the function name...
It works quit good now, but I use the following code now:
code: function OnEvent_DownloadFileComplete(Url, OutFile, Success)
{
if(Success)
{
Debug.Trace('File: ' + OutFile);
WndProfileInformation.ImageElmt_SetImageFile('ImgDisplayPic', OutFile);
}
}
But It doesn't show it in the element, but there does change something. The default image is removed, but the new image is not shown... Do I have to do anything with the OutFile path? Maybe add some slashes...
EDIT2: Missed Marty's post, just had to add to slashes before the path, it works great now! Thanks guys !
This post was edited on 03-02-2007 at 07:15 PM by Yorick.
|
|
03-02-2007 07:04 PM |
|
|
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
Joined: Apr 2004
|
RE: Loading a external image
quote: Originally posted by CookieRevised
Short answer: declare WndProfileInformation as a global variable.
And this should be done when you create the window, like in:
code: WndProfileInformation = MsgPlus.CreateWnd("thing.xml", "WndProfileInformation");
The difference here is the missing "var" prefix, without it it'll get declared as a global variable.
Note: when the window is destroyed, you should delete the variable too!
|
|
03-02-2007 07:23 PM |
|
|
Yorick
Junior Member
Posts: 22
34 / /
Joined: Mar 2007
|
O.P. RE: Loading a external image
I don't know if I need to open a new topic about this, please say if I need to!
I bumped into another problem. I want to show some information, but I don't always have all the information....
Like this:
Profile:
Name
Country (optional)
Age (Optional)
But sometimes I don't have information to fill the country, and I do have information to fill the age. If I do it with static controls, you'll get a gap, because I can't fill country.. anyone a brilliant idea how to do this?
|
|
03-02-2007 07:32 PM |
|
|
CookieRevised
Elite Member
Posts: 15517 Reputation: 173
– / /
Joined: Jul 2003
Status: Away
|
RE: RE: Loading a external image
quote: Originally posted by Mattike
quote: Originally posted by CookieRevised
Short answer: declare WndProfileInformation as a global variable.
And this should be done when you create the window, like in:code: WndProfileInformation = MsgPlus.CreateWnd("thing.xml", "WndProfileInformation");
The difference here is the missing "var" prefix, without it it'll get declared as a global variable.
Note: when the window is destroyed, you should delete the variable too!
Personally I would not recommend declaring variables like that. It is bad practice and prone to errors/bugs if you're not carefull.
Always use var and always declare your global variables outside functions first.
quote: Originally posted by Yorick
I want to show some information, but I don't always have all the information....
Like this:
Profile:
Name
Country (optional)
Age (Optional)
But sometimes I don't have information to fill the country, and I do have information to fill the age. If I do it with static controls, you'll get a gap, because I can't fill country.. anyone a brilliant idea how to do this?
we need far more information to answer this question properly as there are billions of things which you can mean or want to do.
With the information given all I can say is if you don't have the info then don't display it and use a description prefix.
eg:
Profile
Name: John
Country:
Age: 25
EDIT: after seeing your other thread, I understand what you mean. hint: always provide enough details from the start
PS: a control is in that context always static... no control moves around on their own. Static means 'user can not interact with it' (eg: a text label), opposed to dynamic which is changeable by the user (eg: a combobox). Thus it doesn't have anything todo with moving.
Anyways,
Or you could simply move controls, but this will require the use of Windows APIs. This is possible, but certainly not elegant for this purpose.
Or you could instead of making 3 static labels, just make 1 static label and fill it with a string which is a concatenation from the individual variables seperated with a newline character (\n).
eg:
code: var Name = "John";
var Country = "";
var Age = "25";
var ShoeSize = "5";
var Fingers = "10"
var State = "Married";
var Profile = ""; // String to display in first and only label control
If (Name !== "") Profile += "\n" + Name;
If (Country !== "") Profile += "\n" + Country;
if (Age !== "") Profile += "\n" + Age + (Age == 1 ? " year" : " years");
if (ShoeSize !== "") Profile += "\n" + ShoeSize;
if (Fingers !== "") Profile += "\n" + Fingers;
if (Sate !== "") Profile += "\n" + State;
// Remove first NewLine character
Profile = Profile.substr(1);
// Set control text
wndProfileWindow.SetControlText("lblProfile", Profile);
PS: Also notice what I've done with the age. That line adds either "years" or "year" according to what the age is (if age is 1 it will add "year"; thus without the s).
(Age == 1 ? " year" : " years") is called a ternary operation. It is in fact an IF THEN ELSE but written as a single statement on one line. The shown ternary operation is the same as if you would write: code: if (Age == 1) {
return " year"
}
else {
return " years"
}
This post was edited on 03-03-2007 at 01:49 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
|
|
03-02-2007 09:13 PM |
|
|
Eljay
Elite Member
:O
Posts: 2949 Reputation: 77
– / / –
Joined: May 2004
|
RE: RE: RE: Loading a external image
quote: Originally posted by CookieRevised
quote: Originally posted by Mattike
quote: Originally posted by CookieRevised
Short answer: declare WndProfileInformation as a global variable.
And this should be done when you create the window, like in:
code: WndProfileInformation = MsgPlus.CreateWnd("thing.xml", "WndProfileInformation");
The difference here is the missing "var" prefix, without it it'll get declared as a global variable.
Note: when the window is destroyed, you should delete the variable too!
Personally I would not recommend declaring variables like that. It is bad practice and prone to errors/bugs if you're not carefull.
Always use var and always declare your global variables outside functions first.
I think he was referring to removing the var from the statement inside the function so instead of creating a local variable, it would set the already existing global variable.
|
|
03-02-2007 09:23 PM |
|
|
|