Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> niezdefiniowany obiekt w konstruktorze
emil_seba
post
Post #1





Grupa: Zarejestrowani
Postów: 21
Pomógł: 0
Dołączył: 24.05.2010

Ostrzeżenie: (0%)
-----


Witam, mam taki problem, tworze obiekt kin w konstruktorze, jest on dostepny w funkcji drawImage(), natomiast w funkcji dragger() występuje błąd, że kin jest nie zdefiniowane. Mógł by ktoś poradzić mi dlaczego ? Z góry dziękuję.
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <script src="Kinetic-v1.0.0.js"></script>
  5. <script type = "text/javascript">
  6.  
  7.  
  8. function Obrazek(obiekt)
  9. {
  10. this.kin = new Kinetic_2d("obraz");
  11. this.rectX = 0;
  12. this.rectY = 0;
  13. this.rectOfsetX = 0;
  14. this.rectOfsetY = 0;
  15. this.dragingRect = false;
  16. this.boba = obiekt;
  17. this.canvas=null;
  18. this.context=null;
  19.  
  20. this.dragger = function ()
  21. {
  22. var mouseP = this.kin.getMousePos(); // bląd kin jest nie zdefiniowane
  23.  
  24. if(this.dragingRect)
  25. {
  26. this.rectX = mouseP.x - rectOfsetX;
  27. this.rectY = mouseP.y - rectOfserY;
  28. }
  29.  
  30. this.kin.clear();
  31. this.kin.beginRegion();
  32. this.context.drawImage(this.boba,rectX,rectY,this.boba.width,this.boba.height);
  33. this.context.beginPath();
  34. this.context.rect(this.rectX,this.rectY,this.boba.width,this.boba.height);
  35. this.context.closePath();
  36.  
  37. this.kin.addRegionEventListener("onmousedown",function(){
  38. var mouseP = this.kin.getMousePos();
  39. this.dragingRect = true;
  40. this.rectOfsetX = mouseP.x - this.rectX;
  41. this.rectOfsetY = mouseP.y - this.rectY;
  42. });
  43.  
  44. this.kin.addRegionEventListener("onmouseup",function(){
  45. this.dragingRect = false;
  46. });
  47. this.kin.addRegionEventListener("onmouseover",function(){
  48. document.body.style.cursor = "pointer";
  49. });
  50. this.kin.addRegionEventListener("onmouseout",function(){
  51. document.body.style.cursor = "default";});
  52.  
  53. this.kin.closeRegion();
  54. }
  55.  
  56. this.drawImage = function()
  57. {
  58. this.canvas = this.kin.getCanvas();
  59. this.context = this.kin.getContext();
  60.  
  61. this.rectX = this.canvas.width/2 - this.boba.width/2;
  62. this.rextY = this.canvas.height/2 - this.boba.height/2;
  63.  
  64. this.kin.setDrawStage(this.dragger);
  65. }
  66.  
  67. }
  68. window.onload = function(){
  69.  
  70. var im = new Image();
  71. im.onload = function()
  72. {
  73. var zdj = new Obrazek(im);
  74. zdj.drawImage();
  75.  
  76. }
  77. im.src ="Garnek.jpg";
  78.  
  79. }
  80.  
  81.  
  82. </script>
  83. </head>
  84. <body>
  85. <canvas id="obraz" width="400" height="400" style="border-style:solid;" >
  86. Twoja przegladarka nie obsluguje canvas.
  87. </canvas>
  88.  
  89. </body>
  90. </html>
  91.  
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
Cysiaczek
post
Post #2





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




Nie znam się na JS za bardzo, ale mam wrażenie, że chodzi o zasięg zmiennych.


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post
melkorm
post
Post #3





Grupa: Zarejestrowani
Postów: 1 366
Pomógł: 261
Dołączył: 23.09.2008
Skąd: Bydgoszcz

Ostrzeżenie: (0%)
-----


Cytat
this.kin.clear();


Przedmówca dobrze mówi, this odwołuje się do funkcji w której jest użyty, zamiast this, użyj var .


--------------------
Go to the top of the page
+Quote Post
emil_seba
post
Post #4





Grupa: Zarejestrowani
Postów: 21
Pomógł: 0
Dołączył: 24.05.2010

Ostrzeżenie: (0%)
-----


dzięki, var pomogło smile.gif zamiast zmiennych publicznych zrobiłem zmienne prywatne (z użyciem var), tylko funkcje z użyciem this jako metody publiczne.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 20:19