d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Help Html/javascript
Add Reply New Topic New Poll
Member
Posts: 16,498
Joined: Jun 8 2008
Gold: 113.00
Jan 30 2014 01:17am
Code
avatarImage.src = "img/avatar.png";
alert(avatarImage.width);


I'm ttrying to follow a simple tutorial on coding. It will not put my PNG on the canvas.
I've done everything the exact same as the person in the Tut, his picture shows. Mine doesnt.

Any ideas why this might be?

edit/ I meant his says alerts 29, mine alerts 0
Using the same PNG file.

This post was edited by ghdork on Jan 30 2014 01:17am
Member
Posts: 29,723
Joined: Jun 11 2007
Gold: 279.52
Jan 30 2014 01:28am
is ur image in a folder called img?
Member
Posts: 16,498
Joined: Jun 8 2008
Gold: 113.00
Jan 30 2014 01:32am
Quote (AkuuZ @ Jan 30 2014 02:28am)
is ur image in a folder called img?


Yeah.
I've followed the tut verbatim.
Member
Posts: 3,013
Joined: Jan 14 2008
Gold: 213.00
Feb 1 2014 11:11pm
is the image in a folder that is in a folder where the script is.


say you have a folder set up like this


Code
Sitefolder>
pages>
images>
(random.png)
scripts>
(random.js)
styles>


In which case

Code
avatarImage.src = "img/avatar.png";
alert(avatarImage.width);


should be

Code
avatarImage.src = "../img/avatar.png";
alert(avatarImage.width);



but instead its reading it as

Code
Sitefolder>
pages>
scripts>
(random.js)
images>
(random.png)
styles>


The "../" is telling the script to take a step back and then go in to images instead of going in to a folder called images where ever your script is.

Edit:
that the simplest way to do it, otherwise you can just type the whole location like "C:/mycomputer/soandso/soandso/images/random.png"


This post was edited by PumperNickle on Feb 1 2014 11:14pm
Member
Posts: 16,498
Joined: Jun 8 2008
Gold: 113.00
Feb 2 2014 08:51pm
Quote (PumperNickle @ Feb 2 2014 12:11am)
is the image in a folder that is in a folder where the script is.


say you have a folder set up like this


Code
Sitefolder>
                pages>
                images>
                            (random.png)
                scripts>
                            (random.js)
                styles>


In which case

Code
avatarImage.src = "img/avatar.png";
    alert(avatarImage.width);


should be

Code
avatarImage.src = "../img/avatar.png";
    alert(avatarImage.width);



but instead its reading it as

Code
Sitefolder>
                pages>
                scripts>
                            (random.js)
                            images>
                                          (random.png)                         
                styles>


The "../" is telling the script to take a step back and then go in to images instead of going in to a folder called images where ever your script is.

Edit:
that the simplest way to do it, otherwise you can just type the whole location like "C:/mycomputer/soandso/soandso/images/random.png"


I've tried both of those methods... Still not working.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Feb 2 2014 08:57pm
how about you post all the code and screenshot your directory structure? i suspect it's a very simple problem but you're not providing enough information for us to solve it. eg: maybe you're hiding file extensions, so your file is actually named avatar.png.png. or your code is in the wrong place. or missing bracket. or you have code right after which resets it. etc etc

This post was edited by carteblanche on Feb 2 2014 08:58pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll