hotspot_solution.fla.as 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. // javascript Proxy
  2. import com.macromedia.javascript.JavaScriptProxy;
  3. var JS_proxy:JavaScriptProxy = new JavaScriptProxy();
  4. System.useCodepage = true;
  5. // get id from querystring
  6. myURL = this._url;
  7. //myURL = "http://localhost/dokeosSVN/main/plugin/hotspot/hotspot_solution.swf?modifyAnswers=1&exe_id=2&from_db=3";
  8. tmpAr = myURL.split("?");
  9. tmpAr = tmpAr[1].split("&");
  10. id = tmpAr[0].split("=");
  11. id = id[1];
  12. exe_id = tmpAr[1].split("=");
  13. exe_id = exe_id[1];
  14. from_db = tmpAr[2].split("=");
  15. from_db = from_db[1];
  16. // get URL to load lang and hotspot variables
  17. //myURL = this._url;
  18. myPos = myURL.lastIndexOf("/");
  19. myURL = myURL.substring(0, myPos);
  20. myPos = myURL.lastIndexOf("/");
  21. myURL = myURL.substring(0, myPos);
  22. myPos = myURL.lastIndexOf("/");
  23. myURL = myURL.substring(0, myPos);
  24. // movie properties
  25. var movieWidth:Number = 380;
  26. var movieHeight:Number = 400;
  27. // hotspot properties
  28. var startWidth:Number = 0; // \__ if these values are set, shape will be drawn right and down from the mouse;
  29. var startHeight:Number = 0; // /
  30. var pType:String = ""; // possible values: circle, square, poly;
  31. // other settings
  32. var i:Number = 1;
  33. var isDrawing:Boolean = false;
  34. var hotspots_c:Array = new Array('0x4271B5','0xFE8E16','0x45C7F0','0xBCD631','0xD63173','0xD7D7D7','0x90AFDD','0xAF8640','0x4F9242','0xF4EB24','0xED2024','0x3B3B3B');
  35. // make array with all elements
  36. var hotspots:Array = new Array();
  37. // get data from database
  38. this.createEmptyMovieClip("target_mc", 2000);
  39. //_answers
  40. loadVariables(myURL + "/exercice/hotspot_answers.as.php?modifyAnswers="+id+"&exe_id="+exe_id+"&from_db="+from_db, target_mc);
  41. var param_interval:Number = setInterval(checkParamsLoaded, 100);
  42. // language variables
  43. var str_choose:String = "";
  44. var lang_interval:Number
  45. // counter for language (if language can't be loaded after 2 sec,
  46. // english will be loaded
  47. var counter:Number = 0;
  48. // booleans for loading
  49. var langLoaded:Boolean = false;
  50. var varsLoaded:Boolean = false;
  51. var imageLoaded:Boolean = false;
  52. // image preloader
  53. var loadListener:Object = new Object();
  54. loadListener.onLoadComplete = function(){
  55. _root.imageLoaded = true;
  56. _root.showInterface();
  57. }
  58. var mcLoader:MovieClipLoader = new MovieClipLoader();
  59. mcLoader.addListener(loadListener);
  60. var mc:MovieClip = _root.image_mc;
  61. /////////////////////////////////////////////////////////////////////////////////
  62. // FUNCTIONS
  63. /////////////////////////////////////////////////////////////////////////////////
  64. // show hotspots, user can't click anymore
  65. function showHotspots(num){
  66. for(j=1;j<=_root.hotspots.length;j++){
  67. _root.map_mc["hotspot"+j]._alpha = num;
  68. }
  69. }
  70. function showUserpoints(num){
  71. for(j=1;j<=_root.hotspots.length;j++){
  72. _root["hotspot_answer"+j]._alpha = num;
  73. if(num==0){
  74. _root["hotspot_answer"+j].hotspot_mc._visible = false;
  75. }else{
  76. _root["hotspot_answer"+j].hotspot_mc._visible = true;
  77. }
  78. }
  79. }
  80. function showInterface(){
  81. if((_root.langLoaded == true) and (_root.varsLoaded == true) and (_root.imageLoaded == true)){
  82. _root.showUserpoints(100);
  83. _root.showHotspots(100);
  84. _root.loading_mc._visible = false;
  85. }
  86. }
  87. // get language file
  88. function getLang(){
  89. counter++;
  90. if (_root.lang_mc.done != undefined) {
  91. _root.show_userPoints_btn.label = _root.lang_mc.showUserPoints;
  92. _root.show_hotspots_btn.label = _root.lang_mc.showHotspots;
  93. // check if interface can be showed (if everything else is loaded)
  94. _root.langLoaded = true;
  95. _root.showInterface();
  96. // clear interval
  97. clearInterval(_root.lang_interval);
  98. }else if(counter==20){
  99. // clear interval
  100. clearInterval(_root.lang_interval);
  101. // set counter to zero
  102. _root.counter = 0;
  103. // set new interval (get english version)
  104. loadVariables(myURL + "/lang/english/hotspot.inc.php", _root.lang_mc);
  105. _root.lang_interval = setInterval(getLang, 100);
  106. }
  107. }
  108. function checkParamsLoaded() {
  109. if (target_mc.done != undefined) {
  110. // once we know the language, get language-variables from language file
  111. language = target_mc["hotspot_lang"];
  112. _root.createEmptyMovieClip("lang_mc", 2001);
  113. //loadVariables(myURL + "/lang/" + language + "/hotspot.inc.php", _root.lang_mc);
  114. loadVariables(myURL + "/exercice/hotspot.inc.php", _root.lang_mc);
  115. _root.lang_interval = setInterval(getLang, 100);
  116. // start loading external image
  117. _root.mcLoader.loadClip("../../courses/" + target_mc["courseCode"] + "/document/images/" + target_mc["hotspot_image"], mc);
  118. // make needed array's: filled if hotspot exists, empty if not
  119. for(m = 1; m <= 12; m++){
  120. // make seperate lists
  121. if(target_mc["hotspot_" + m]=="true"){
  122. // add to general list
  123. tmpAr = Array();
  124. tmpAr.push(m);
  125. tmpAr.push(target_mc["hotspot_" + m + "_type"]);
  126. _root.hotspots.push(tmpAr);
  127. if (target_mc["hotspot_" + m + "_type"] != 'poly' && target_mc["hotspot_" + m + "_type"] != 'delineation'){
  128. // x;y|height|width
  129. _root["p_hotspot_" + m] = new Array;
  130. $coordinates = target_mc["hotspot_" + m + "_coord"].split("|");
  131. $tmp_xy = $coordinates[0].split(";");
  132. $x = $tmp_xy[0];
  133. $y = $tmp_xy[1];
  134. $height = $coordinates[1];
  135. $widht = $coordinates[2];
  136. _root["p_hotspot_" + m].push($x);
  137. _root["p_hotspot_" + m].push($y);
  138. _root["p_hotspot_" + m].push($height);
  139. _root["p_hotspot_" + m].push($widht);
  140. }else{
  141. // p1_x;p1_y|p2_x;p2_y|...
  142. _root["p_hotspot_" + m] = new Array();
  143. $coordinates = target_mc["hotspot_" + m + "_coord"].split("|");
  144. for(k=0;k<$coordinates.length;k++){
  145. $tmp_xy = $coordinates[k].split(";");
  146. tempArray = Array();
  147. tempArray.push($tmp_xy[0]);
  148. tempArray.push($tmp_xy[1]);
  149. _root["p_hotspot_" + m].push(tempArray);
  150. }
  151. }
  152. }else{
  153. _root["p_hotspot_" + m] = Array();
  154. }
  155. }
  156. // set border around image
  157. _root.map_mc._width = int(target_mc.hotspot_image_width) + 1;
  158. _root.map_mc._height = int(target_mc.hotspot_image_height) + 1;
  159. // draw the hotspots
  160. drawShapes();
  161. // check if interface can be showed (if everything else is loaded)
  162. _root.varsLoaded = true;
  163. _root.showInterface();
  164. // clear interval
  165. clearInterval(param_interval);
  166. }
  167. }
  168. // draw the shapes that are given from the database
  169. function drawShapes(){
  170. // draw points where user clicked
  171. _root.drawPoints();
  172. // draw hotspots
  173. for (var j:String in hotspots) {
  174. if(j <> ""){
  175. // +1 because array names starts from 1
  176. _root.i = int(j) + 1;
  177. // -1 because array values starts from 0
  178. _root.pType = _root.hotspots[_root.i - 1][1];
  179. if(_root.pType=="poly" || _root.pType=="delineation"){
  180. drawPoly();
  181. }
  182. else{
  183. drawShape(true);
  184. }
  185. _root.map_mc["hotspot" + _root.i]._alpha = 0;
  186. }
  187. }
  188. }
  189. function drawPoints(){
  190. answers = _root.target_mc.p_hotspot_answers.split("|");
  191. if(answers[0]!=''){
  192. j = 1;
  193. k = 500;
  194. for(var z:String in answers){
  195. if(target_mc["hotspot_"+j+"_type"]=="delineation")
  196. {
  197. // trace poly
  198. delineation_coords = answers[j-1].split("/");
  199. drawDelineation(j, delineation_coords);
  200. }
  201. else
  202. {
  203. xy = answers[j-1].split(";");
  204. $x = xy[0];
  205. $y = xy[1];
  206. // create new hotspot
  207. _root.createEmptyMovieClip("hotspot_answer" + j, k);
  208. // attach correct type of hotspot
  209. _root["hotspot_answer" + j].attachMovie("numbers", "hotspot_mc", _root["hotspot_answer" + j].getNextHighestDepth());
  210. _root["hotspot_answer" + j].hotspot_mc._width = 33;
  211. _root["hotspot_answer" + j].hotspot_mc._height = 22;
  212. _root["hotspot_answer" + j].hotspot_mc._x = int($x) + _root.map_mc._x;
  213. _root["hotspot_answer" + j].hotspot_mc._y = int($y) + _root.map_mc._y;
  214. _root["hotspot_answer" + j].hotspot_mc.order_txt.text = int(j);
  215. _root["hotspot_answer" + j].hotspot_mc._visible = false;
  216. _root["hotspot_answer" + j]._alpha = 0;
  217. }
  218. j++;
  219. k++;
  220. }
  221. }
  222. }
  223. function drawShape(userDrawing){
  224. // create new hotspot
  225. _root.map_mc.createEmptyMovieClip("hotspot" + _root.i, _root.i);
  226. // attach correct type of hotspot
  227. _root.map_mc["hotspot" + _root.i].attachMovie(_root.pType, "hotspot_mc", _root.map_mc["hotspot" + _root.i].getNextHighestDepth());
  228. _root.map_mc["hotspot" + _root.i].hotspot_mc._visible = true;
  229. _root.map_mc["hotspot" + _root.i].hotspot_mc.center_mc._alpha = 60;
  230. _root.map_mc["hotspot" + _root.i].hotspot_mc._x = _root["p_hotspot_"+ _root.i][0];
  231. _root.map_mc["hotspot" + _root.i].hotspot_mc._y = _root["p_hotspot_"+ _root.i][1];
  232. _root.map_mc["hotspot" + _root.i].hotspot_mc._width = _root["p_hotspot_"+ _root.i][2];
  233. _root.map_mc["hotspot" + _root.i].hotspot_mc._height = _root["p_hotspot_"+ _root.i][3];
  234. colorchange = new Color(_root.map_mc["hotspot" + _root.i].hotspot_mc);
  235. colorchange.setRGB(_root.hotspots_c[_root.i - 1]);
  236. }
  237. // when black lines of hotspots are deleted, draw the exact same poly with coordinates
  238. // that are saved in the array
  239. function drawPoly(){
  240. // create empty movieclip
  241. _root.map_mc.createEmptyMovieClip("hotspot" + _root.i, _root.i);
  242. // begin filling the movieclip
  243. _root.map_mc["hotspot" + _root.i].beginFill(_root.hotspots_c[_root.i - 1], 60);
  244. // set linestyle
  245. _root.map_mc["hotspot" + _root.i].lineStyle(1, _root.hotspots_c[_root.i - 1], 100);
  246. // move mouse to first coordinate
  247. _root.map_mc["hotspot" + _root.i].moveTo(_root["p_hotspot_"+_root.i][0][0],_root["p_hotspot_"+_root.i][0][1]);
  248. // draw lines to all coordinates
  249. v = _root["p_hotspot_"+_root.i].length;
  250. for (k=1;k<v;k++){
  251. _root.map_mc["hotspot" + _root.i].lineTo(_root["p_hotspot_"+_root.i][k][0],_root["p_hotspot_"+_root.i][k][1]);
  252. }
  253. // attach first and last coordinates
  254. _root.map_mc["hotspot" + _root.i].lineTo(_root["p_hotspot_"+_root.i][0][0],_root["p_hotspot_"+_root.i][0][1]);
  255. // stop filling the movieclip
  256. _root.map_mc["hotspot" + _root.i].endFill();
  257. }
  258. function drawDelineation(level, coords){
  259. // create empty movieclip
  260. _root.map_mc.createEmptyMovieClip("hotspot_delineation" + level, 2000+level);
  261. // begin filling the movieclip
  262. _root.map_mc["hotspot_delineation" + level].beginFill(0xFFFFFF, 60);
  263. // set linestyle
  264. _root.map_mc["hotspot_delineation" + level].lineStyle(1,0x000000, 100);
  265. // move mouse to first coordinate
  266. xy_origin = coords[0].split(";");
  267. _root.map_mc["hotspot_delineation" + level].moveTo(xy_origin[0],xy_origin[1]);
  268. // draw lines to all coordinates
  269. v = coords.length;
  270. for (k=1;k<v;k++){
  271. xy = coords[k].split(";");
  272. _root.map_mc["hotspot_delineation" + level].lineTo(xy[0],xy[1]);
  273. }
  274. // attach first and last coordinates
  275. _root.map_mc["hotspot_delineation" + level].lineTo(xy_origin[0],xy_origin[1]);
  276. // stop filling the movieclip
  277. _root.map_mc["hotspot_delineation" + level].endFill();
  278. }
  279. function jsdebug(debug_string){
  280. _root.JS_proxy.jsdebug(debug_string);
  281. }