Gets the URL for the provided image element id.
The images in apps are not always static, they sometimes change based on user or other events. getImageURL()
can be used to access the URL of the image displayed for an image element ID.
Click the button to change the character image from the dog to the bee and back again.
// Click the button to change the character image from the dog to the bee and back again. var imageId = "character"; var dogImageURL = "http://studio.code.org/blockly/media/skins/applab/static_avatar.png"; var beeImageURL = "http://studio.code.org/blockly/media/skins/bee/static_avatar.png"; image(imageId, dogImageURL); button("changeButton", "Change Character"); onEvent("changeButton", "click", function() { if (getImageURL(imageId).includes("bee")) { setImageURL(imageId, dogImageURL); } else { setImageURL(imageId, beeImageURL); } });
// Display the URL of the Code.org logo. image("logo", "http://code.org/images/logo.png"); write(getImageURL("logo"));
getImageURL(id);
Name | Type | Required? | Description |
---|---|---|---|
id | string | The unique identifier for the screen element. Must begin with a letter, contain no spaces, and may contain letters, digits, - and _. |
Returns a string containing image url for the provided id.
Found a bug in the documentation? Let us know at documentation@code.org