Jump to content

echofool

Members
  • Content Count

    58
  • Joined

  • Last visited

Community Reputation

1 Neutral

About echofool

  • Rank
    Newbie
  1. How though ?its using % based on user's screen... i tried this: function mousePos(e){var curleft = curtop = 0; if (e.offsetParent) { do { curleft += e.offsetLeft; curtop += e.offsetTop; } while (e = e.offsetParent); }} canvas = document.getElementById("canvas"); ctx = canvas.getContext("2d");canvas.addEventListener("mousedown", mousePos, false); But it doesn't work =/ curleft and curtop remain as 0
  2. Hey I am stuck trying to get the mouse position in a canvas relative to the canvas and not the entire page. The position of the canvas in my page effects what e.pageX and e.pageY are which is a problem. Is there a way to do this so canvas position in a page is not affecting it?I used this thinking it would be relative to canvas only but it is not the case: canvas = document.getElementById("canvas"); ctx = canvas.getContext("2d"); canvas.addEventListener("mousedown", mousePos, false); Any ideas ? Is it even possible?
  3. Well the array im suppose to be creating from a database which has: x : y : image so could the array be made like to save lines of code? var positions = [ [0, 1] = 1, [1, 1] = 1 ];
  4. Hey Need help with creating an array in javascript. I did this: var positions = new Array();positions[0][0] = 0;positions[1][0] = 1;positions[0][1] = 1;positions[1][1] = 1; The idea i had was the two sqaure brackets will represet a map grid reference, but i was wondering why it was not working.. I get this error: Any ideas why this happens ? Hope you can help!
  5. Yeh i mistaken linked the wrong link - refresh you will see dx and dy are now offset_x and offsey_y which are used in draw function.
  6. Hey I've asked every where with this problem and not one person seems to know the answer. I'm trying to make drag-able map in canvas. I have two current solutions to make it work but both are plagued with some kind of strange problem. My first method is: function mousePos(e){ mousex = e.pageX; mousey = e.pageY;canvas.addEventListener("mousemove", movePos, false);} function movePos(e){ offset_x = e.pageX-mousex; // used in draw function offset_y = e.pageY-mousey; // used in draw function} How ever this won't work because if i try to drag a second time, it resets back to 0 offset because its not adding it on to previous offset values. So i then changed it to: offset_x += e.pageX-mousex; // used in draw function offset_y += e.pageY-mousey; // used in draw function This solved the reset issue but now when i click and drag it goes so fast off the screen its pretty much useless to use. It also continues in the same direction regardless of mouse movement direction too. any ideas how i solve it - i know its a long shot cos no one has found the solution yet and i've asked literally all forums i can think of.
  7. Thanks for the information i will do some testing with it
  8. Hmm thats strange, the original script had it worded like that but doesn't do what my localhost script is doing. V.odd. the only difference on the original script is the function call is like this: onFailure: Loader.error error: function() {alert('Error, refresh window.');} It didn't send a variable like my edited version did.. could that change the way it behaves? Seems unlikely though.. EDIT yup i was correct, if i remove the ('Data error') part it seems to solve the problem.
  9. It calls a function like this: onFailure: Loader.error('data error!') This is the only error with that "data error" message, so i know which onFailure it is. The function it calls is: var Loader = {//other js stuff error: function(a) {alert('Error! ' + a);} // other js stuff}
  10. I mistyped i'm using mootools but the loading script is longgg it loads alot of stuff - but the documentation has this: ( i use mootools) Thats it lol - epic helpful their documentation. The error status code im assuming is the the page status when you send the request - which is 200 according to firebug. See attatchment.
  11. Difficult to show all of it cos its over a few thousand lines long. Theres no documentation cos I have made the thing myself over many months ! The returned arrays are all syntax'd correctly. I'll have to keep searching for the cause, very hard to debug JS
  12. The odd thing is - the stuff still loads =/ so i dunno why its still erroring. What is it checking for onFailure? Does it have to be given a certain value for it to count as a failure =/? That then would help me know what i am looking for
  13. Hey, I have a javascript issue, where by im getting an error but cannot work out why. Im compiling data and using an onFailure to load an error alert. But from what i can tell it should not error. This is my script: startLoading: function() {Loader.busy();Loader.unload();Loader.result.innerHTML = 'Loading data...';var myRequest = new Request.JSON({ url: '?load/user', onSuccess: function(obj){user.nick = obj.username;user.id = obj.id;user.setStartPos(obj.x*1,obj.y*1);user.map = obj.map_id*1;if (obj.aid)alarm.join(obj.aid);elseLoader.loadImages(); },onFailure: Loader.error('Data error!')}); myRequest.send();} According to my browser the data being called back is: But i get the "Data error" alert =/ how on earth can i debug where the problem might be coming from?
  14. Hey, I made a forum which is meant to popular the select box to show total number of days based on the month i selected but it is not working. Here is my JS: function daysInMonth(month,year) {var dd = new Date(year, month, 0);return dd.getDate();} function setDayDrop(dyear, dmonth, dday) {var year = dyear.options[dyear.selectedIndex].value;var month = dmonth.options[dmonth.selectedIndex].value;var day = dday.options[dday.selectedIndex].value;if (day == ' ') {var days = (year == ' ' || month == ' ')? 31 : daysInMonth(month,year);dday.options.length = 0;dday.options[dday.options.length] = new Option(' ',' ');for (var i = 1; i <= days; i++)dday.options[dday.options.length] = new Option(i,i); }} function setDay() {var year = document.getElementById('year');var month = document.getElementById('month');var day = document.getElementById('day');setDayDrop(year,month,day);} document.getElementById('year').onchange = setDay;document.getElementById('month').onchange = setDay; My html: <select name="year" id="year" size="1"><option value="" selected="selected"> </option><option value="2000">2000</option><option value="2001">2001</option><option value="2002">2002</option></select><select name="month" id="month" size="1"><option value="" selected="selected"> </option><option value="1">January</option><option value="2">February</option><option value="3">March</option><option value="4">April</option><option value="5">May</option><option value="6">June</option><option value="7">July</option><option value="8">August</option><option value="9">September</option><option value="10">October</option><option value="11">November</option><option value="12">December</option></select> <select name="day" id="day" size="1"><option value=" " selected="selected"> </option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option></select> Can any one see the mistake i have made?
  15. Thanks for the tip Shadow
×
×
  • Create New...