PageRenderTime 82ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/cutload/CutLoad/cookies/Fun.as

http://cutload.googlecode.com/
ActionScript | 612 lines | 368 code | 7 blank | 237 comment | 49 complexity | 978e89a2fb322cd4616abf366b255d70 MD5 | raw file
  1. package CutLoad.cookies
  2. {
  3. import CutLoad.CutLoad;
  4. import flash.display.BitmapData;
  5. import flash.display.DisplayObject;
  6. import flash.display.Graphics;
  7. import flash.display.LoaderInfo;
  8. import flash.display.MovieClip;
  9. import flash.display.Sprite;
  10. import flash.display.StageDisplayState;
  11. import flash.events.MouseEvent;
  12. import flash.external.ExternalInterface;
  13. import flash.geom.Point;
  14. import flash.geom.Rectangle;
  15. import flash.net.URLRequest;
  16. import flash.net.navigateToURL;
  17. import flash.system.ApplicationDomain;
  18. /**
  19. * ????
  20. * @author smallerbird mail:smallerbird@gmail.com site:www.mkigm.com QQ?:49983196
  21. *
  22. */
  23. public class Fun
  24. {
  25. /**
  26. * Rectangle?? containsPoint????????????,????????
  27. * @param rect Rectangle??
  28. * @param p ?????
  29. * @return
  30. *
  31. */
  32. public static function rectContainsPoint(rect:Rectangle,p:Point):Boolean{
  33. if((p.x>=rect.x&&p.x<=rect.x+rect.width)&&(p.y>=rect.y&&p.y<=rect.y+rect.height)){
  34. return true;
  35. }
  36. return false
  37. }
  38. /**
  39. * ? Sprite??????????
  40. * @param sp
  41. * @param funClick ?? function(e:MouseEvent):void
  42. * @param buttonMode
  43. *
  44. */
  45. public static function addMouseClickForSprite(sp:Sprite,funClick:Function,buttonMode:Boolean=true):void{
  46. sp.mouseChildren=false;
  47. sp.buttonMode=true;
  48. sp.addEventListener(MouseEvent.CLICK,funClick);
  49. }
  50. /**
  51. * ?? Rectangle?? ???
  52. * @param rect
  53. * @return
  54. *
  55. */
  56. public static function rectCenterPoint(rect:Rectangle):Point{
  57. return new Point(rect.x+rect.width/2,rect.y+rect.height/2);
  58. }
  59. /**
  60. * ?? Rectangle??????
  61. * @param rect Point????
  62. * @return
  63. *
  64. */
  65. public static function rect4Point(rect:Rectangle):Array{
  66. var arr:Array=new Array();
  67. arr.push(new Point(rect.x,rect.y));
  68. arr.push(new Point(rect.x+rect.width,rect.y));
  69. arr.push(new Point(rect.x+rect.width,rect.y+rect.height));
  70. arr.push(new Point(rect.x,rect.y+rect.height));
  71. return arr;
  72. }
  73. /**
  74. * ?????????? ??????????
  75. * @param arr
  76. * @return
  77. *
  78. */
  79. public static function clrArrayRepeat(arr:Array):Array{
  80. var arrReturn:Array=new Array();
  81. for(var i:Number=0;i<arr.length;i++){
  82. var isAdd:Boolean=false;
  83. for(var j:Number=0;j<arrReturn.length;j++){
  84. if(arr[i]==arrReturn[j]){
  85. isAdd=true;
  86. break;
  87. }
  88. }
  89. if(!isAdd) arrReturn.push(arr[i])
  90. }
  91. return arrReturn;
  92. }
  93. /**
  94. * ????js
  95. * @param js??
  96. * @param arguments
  97. * @return
  98. *
  99. */
  100. public static function jscall(functionName:String):String{
  101. functionName="javascript:"+functionName;
  102. Fun.goToUrl(functionName,"_self");
  103. return functionName
  104. }
  105. /**
  106. * ????????js??
  107. * @param functionName
  108. * @param closure
  109. *
  110. */
  111. public static function jscallback(functionName:String, closure:Function):void
  112. {
  113. ExternalInterface.addCallback(functionName,closure);
  114. }
  115. /**
  116. * ???????????????????<p>???http://localhost/testswf/test_url.swf ??==> http://localhost/testswf/ </p>
  117. * <p> file:///C|/Documents%20and%20Settings/Administrator/??/test%5Furl.swf ??==>file:///C|/Documents%20and%20Settings/Administrator/??/</p>
  118. * @param strPath
  119. * @return
  120. *
  121. */
  122. public static function getFilePathStr(strPath:String):String{
  123. var str1:String="http://";
  124. var indexTem:Number;
  125. var strStr:String=".swf";
  126. if (strPath.indexOf(str1)==0) {
  127. indexTem=strPath.lastIndexOf(strStr);
  128. } else {
  129. indexTem=strPath.lastIndexOf(strStr);
  130. }
  131. if (indexTem==-1) {
  132. return "";
  133. }
  134. strPath=strPath.substr(0,indexTem) + strStr;
  135. //
  136. strStr="/";
  137. if (strPath.indexOf(str1)==0) {
  138. indexTem=strPath.lastIndexOf(strStr);
  139. } else {
  140. indexTem=strPath.lastIndexOf(strStr);
  141. }
  142. if (indexTem==-1) {
  143. return "";
  144. }
  145. strPath=strPath.substr(0,indexTem) + strStr;
  146. return strPath;
  147. }
  148. /**
  149. * ??????
  150. * @param url
  151. * @param strTarget
  152. *
  153. */
  154. public static function goToUrl(url:String,strTarget:String="_blank"):void{
  155. if(url=="") return;
  156. navigateToURL(new URLRequest(url),strTarget);
  157. }
  158. /**
  159. * ???Object?????????????????
  160. * @param fromObj ???????
  161. * @param toObj ???????
  162. *
  163. */
  164. public static function appendObj(fromObj:Object,toObj:Object):void{
  165. //trace("appendObj-------------------")
  166. for(var str:String in fromObj){
  167. //trace(str+":"+fromObj[str]);
  168. toObj[str]=fromObj[str]
  169. }
  170. /*trace("??????????")
  171. for(var str1:String in toObj){
  172. trace(str1+":"+toObj[str1]);
  173. }*/
  174. }
  175. /**
  176. * ?????
  177. * @param str ??????
  178. * @param seachWord ???????
  179. * @param repWord ?????
  180. *
  181. */
  182. public static function replace(str:String,seachWord:String,repWord:String):String{
  183. var myPattern:RegExp =new RegExp(seachWord,"g");
  184. return (str.replace(myPattern,repWord));
  185. }
  186. //??---------------------
  187. /**
  188. * ?????????????????
  189. * @param arrObj ?????
  190. * @param startx ????x
  191. * @param starty ????y
  192. * @param space ??
  193. * @param maxLen ?????????????????????.
  194. * @return ????
  195. */
  196. public static function setStartList(arrObj:Array,startx:Number,starty:Number,space:Number,maxLen:Number=0):Number{
  197. var numLen:Number=0;
  198. for(var i:Number=0;i<arrObj.length;i++){
  199. var objTem:Object=arrObj[i]
  200. if(i==0){
  201. objTem=arrObj[i]
  202. objTem.x=startx;
  203. objTem.y=starty;
  204. numLen+=objTem.getShowWidth()+space;
  205. }else{
  206. var objTem1:Object=arrObj[i-1];
  207. objTem.x=objTem1.getXYRightUp().x+space;
  208. objTem.y=starty;
  209. numLen+=objTem.getShowWidth();
  210. }
  211. }
  212. //?????0???
  213. if(maxLen!=0){
  214. var xx:Number=getCenterXY(maxLen,numLen);
  215. var temMove:Number=Math.abs(startx-xx);
  216. MoveSomeXY(arrObj,temMove,0);
  217. }
  218. return numLen
  219. }
  220. //
  221. /**
  222. * ?????x?y??
  223. * @param startxy ????????x?y
  224. * @param maxWH ???????
  225. * @param len ???????????
  226. * @return ?????x???y
  227. *
  228. */
  229. public static function getCenterXY(maxWH:Number,len:Number):Number{
  230. var w2:Number=0;
  231. if(maxWH>len) w2=(maxWH-len)/2;
  232. return w2;
  233. }
  234. /**
  235. * ???????????????????????????:mc1,mc2,mc3.. ??????????????[mc1,mc2,mc3..] ?????????
  236. * ??????????????
  237. * @param parent ?????????
  238. * @param propertiesName ???????????????mc1,mc2,mc3 ????????:mc
  239. * @param end ?????????,???mc1,mc2,mc3 ??????????3
  240. * @param start ?????????????0, ???mc1,mc2,mc3 ??????????1
  241. * @return
  242. *
  243. */
  244. public static function getThisArry(parent:Object,propertiesName:String,end:Number,start:Number=0):Array{
  245. var arr:Array=new Array();
  246. for(var i:Number=start;i<=end;i++){
  247. arr.push(parent[propertiesName+i])
  248. }
  249. return arr;
  250. }
  251. /**
  252. * ????DisplayObject?????????????
  253. * @param obj ?????
  254. * @param x x??
  255. * @param y y??
  256. * @param parent ??
  257. *
  258. */
  259. public static function DisplayObjectSetXY(obj:DisplayObject,x:Number,y:Number,parent:Sprite=null):void{
  260. obj.x=x;
  261. obj.y=y;
  262. if(parent!=null) parent.addChild(obj);
  263. }
  264. /**
  265. * ??DisplayObject
  266. * @param obj
  267. *
  268. */
  269. public static function DisplayObjectKillMe(obj:DisplayObject):void{
  270. if(obj.parent!=null){
  271. obj.parent.removeChild(obj);
  272. }
  273. }
  274. /**
  275. * ???????x?y????????
  276. * @param arrObj ????
  277. * @param xyOffset x???????
  278. * @param xyOffset y???????
  279. *
  280. */
  281. public static function MoveSomeXY(arrObj:Array,xOffset:Number=0,yOffset:Number=0):void{
  282. var w:Number=0,h:Number=0
  283. for(var i:Number=0;i<arrObj.length;i++){
  284. if(i!=0){
  285. if(xOffset!=0){
  286. w=arrObj[i-1].x+arrObj[i-1].width;
  287. }else{
  288. w=0
  289. }
  290. if(yOffset!=0){
  291. h=arrObj[i-1].y+arrObj[i-1].height;
  292. }else{
  293. h=0;
  294. }
  295. }
  296. arrObj[i].x+=xOffset+w
  297. arrObj[i].y+=yOffset+h
  298. }
  299. }
  300. /**
  301. * ???????????? ,?????????
  302. * @param p_name
  303. * @return
  304. *
  305. */
  306. public static function getStrClassObject(p_name : String):Object
  307. {
  308. try
  309. {
  310. var myclass:Class=ApplicationDomain.currentDomain.getDefinition(p_name) as Class;
  311. return new myclass();
  312. }
  313. catch (p_e : ReferenceError)
  314. {
  315. throw new Error("?? " + p_name + " ???");
  316. return null;
  317. }
  318. return null;
  319. }
  320. /**
  321. * ????ApplicationDomain?????
  322. *
  323. * @param p_name ???????????????,? net.eidiot.net.SWFLoader
  324. * @param p_info ??swf?LoadInfo???????????
  325. * @return ??????????????null
  326. */
  327. public static function getClass(p_name : String, p_info:LoaderInfo = null):Class
  328. {
  329. try
  330. {
  331. if (p_info == null)
  332. return ApplicationDomain.currentDomain.getDefinition(p_name) as Class;
  333. return p_info.applicationDomain.getDefinition(p_name) as Class;
  334. }
  335. catch (p_e : ReferenceError)
  336. {
  337. throw new Error("?? " + p_name + " ???");
  338. return null;
  339. }
  340. return null;
  341. }
  342. /**
  343. * ??????????????
  344. * @param tartget ??
  345. * @return ?????
  346. *
  347. */
  348. public static function setTopDepath(tartget:DisplayObject):Number{
  349. if(tartget==null) return -1;
  350. if(tartget.parent==null) throw new Error("??????");
  351. var paretn:Sprite=tartget.parent as Sprite;
  352. var sp:Sprite=new Sprite();
  353. paretn.addChild(sp);
  354. var index:Number=paretn.getChildIndex(sp);
  355. paretn.swapChildren(sp,tartget);
  356. paretn.removeChild(sp);
  357. return index;
  358. }
  359. /**
  360. * ??Sprite???????
  361. * @param sp
  362. *
  363. */
  364. public static function clearAllChild(sp:Sprite):void{
  365. for(var i:Number=0;i<sp.numChildren;i++){
  366. var spTem:DisplayObject=sp.getChildAt(i);
  367. sp.removeChild(spTem);
  368. spTem=null;
  369. }
  370. CutLoad.CutLoad.OptimizeMemory();
  371. }
  372. /**
  373. * ????????????????: ??,?,?
  374. * @param t ??
  375. * @return ???? ["??","?","?"]
  376. *
  377. */
  378. /**
  379. * ????????????????: ??,?,?
  380. * @param t ??
  381. * @param isSec ?????? ? true ?? false
  382. * @return
  383. *
  384. */
  385. public static function getTimeFormat(t:Number,isSec:Boolean=true):Array{
  386. var arrReturn:Array=new Array();
  387. var sec:Number=t;
  388. if(!isSec) sec=Math.floor(t/1000);
  389. var min:Number=0;
  390. var hour:Number=0;
  391. if(sec>60){
  392. hour=Math.floor(sec/3600);
  393. sec=sec-hour*3600;
  394. min=Math.floor(sec/60);
  395. sec=sec-min*60;
  396. }
  397. var strSec:String=sec>9?String(sec):"0"+sec;
  398. var strMin:String=min>9?String(min):"0"+min;
  399. var strHour:String=min>9?String(min):"0"+min;
  400. arrReturn.push(strHour);
  401. arrReturn.push(strMin);
  402. arrReturn.push(strSec);
  403. return arrReturn;
  404. }
  405. /**
  406. * ??????????
  407. * @param char1 ???1 ??:-
  408. * @param char2 ???2 ??:
  409. * @param char3 ???3 ??: :
  410. * @return ????:?-?-? ??:?:?
  411. *
  412. */
  413. public static function getNowDateTimeStr(char1:String="-",char2:String=" ",char3:String=":"):String{
  414. var date:Date=new Date();
  415. return date.getFullYear()+char1+(date.getMonth()+1)+char1+date.getDate()+char2+date.getHours()+char3+date.getMinutes()+char3+date.getSeconds();
  416. }
  417. /**
  418. * ???????????
  419. * @param char1 ???1 ??:-
  420. * @return
  421. *
  422. */
  423. public static function getNowDateStr(char1:String="-"):String{
  424. var date:Date=new Date();
  425. return date.getFullYear()+char1+(date.getMonth()+1)+char1+date.getDate();
  426. }
  427. /**
  428. * ????????
  429. * @param isZero ????????0???
  430. * @return [??,?,?]
  431. *
  432. */
  433. public static function getNowTimeArr(isZero:Boolean=false):Array{
  434. var arrReturn:Array=new Array();
  435. var now:Date=new Date();
  436. var hour:Number=now.getHours();
  437. var min:Number=now.getMinutes();
  438. var sec:Number=now.getSeconds();
  439. var strZero:String=isZero==true?"0":"";
  440. arrReturn.push(hour>9?String(hour):strZero+hour);
  441. arrReturn.push(min>9?String(min):strZero+min);
  442. arrReturn.push(sec>9?String(sec):strZero+sec);
  443. return arrReturn;
  444. }
  445. /**
  446. * ???????:
  447. * @param isZero ????????0???
  448. * @return ???:??:?:?
  449. *
  450. */
  451. public static function getNowTimeStr(isZero:Boolean=false):String{
  452. var arr:Array=getNowTimeArr(isZero);
  453. return arr[0]+":"+arr[1]+":"+arr[2];
  454. }
  455. /**
  456. * ??PI?
  457. * @param t ????????????????PI?,????Math.PI
  458. * @return
  459. *
  460. */
  461. public static function getPI(t:Number=0):Number{
  462. switch(t){
  463. case 1:
  464. return 3.1;
  465. break;
  466. case 2:
  467. return 3.14
  468. break;
  469. case 3:
  470. return 3.141
  471. break;
  472. case 4:
  473. return 3.1415
  474. break;
  475. case 5:
  476. return 3.14159
  477. break;
  478. case 6:
  479. return 3.141592
  480. break;
  481. case 7:
  482. return 3.1415926;
  483. break;
  484. default:
  485. return Math.PI;
  486. break;
  487. }
  488. }
  489. /**
  490. * ?????
  491. * @param angle ??
  492. * @param isPI PI???????
  493. * @return
  494. *
  495. */
  496. public static function angleToRadian(angle:Number,isPI:Boolean=true):Number{
  497. var pi:Number=isPI?getPI():getPI(4)
  498. return angle*pi/180
  499. }
  500. /**
  501. * ?????
  502. * @param radian ??
  503. * @param isPI PI???????
  504. * @return
  505. *
  506. */
  507. public static function radianToAngle(radian:Number,isPI:Boolean=true):Number{
  508. var pi:Number=isPI?getPI():getPI(4)
  509. return radian*180/pi
  510. }
  511. /**
  512. * ??????? ??:mkigm.txt ???txt ???????????
  513. * @param fileName ???
  514. * @return
  515. *
  516. */
  517. public static function getFileTypeName(fileName:String):String{
  518. fileName=fileName.toLocaleLowerCase();
  519. var arr:Array=fileName.split(".");
  520. return arr[arr.length-1];
  521. }
  522. /**
  523. * ??????????????????????
  524. * @param arr
  525. * @param isClockwise true:??? false???
  526. * @return
  527. *
  528. */
  529. public static function roation2Array(arr:Array,isClockwise:Boolean=true):Array{
  530. var arrRoation:Array=new Array();
  531. if(isClockwise){
  532. for(var i:Number=0;i<arr[0].length;i++){
  533. var arrTem:Array=new Array();
  534. for(var j:Number=arr.length-1;j>=0;j--){
  535. arrTem.push(arr[j][i]);
  536. }
  537. arrRoation.push(arrTem);
  538. }
  539. }else{
  540. for(var k:Number=arr[0].length-1;k>=0;k--){
  541. var arrTem1:Array=new Array();
  542. for(var l:Number=0;l<arr.length;l++){
  543. arrTem1.push(arr[l][k]);
  544. }
  545. arrRoation.push(arrTem1);
  546. }
  547. }
  548. return arrRoation;
  549. }
  550. /**
  551. * ???????
  552. * <p>??:var obj:Object = {a:1,b:2,c:"abcdef",d:"adasdfasdf",eeee:[1,2,3,"4",{id:1,name:"??"}]};<br>varDescribe(obj);<br>?????{a:1,b:2,c:"abcdef",d:"adasdfasdf",eeee:[1,2,3,"4",{id:1,name:"??"}]}</p>
  553. * @param obj ??????
  554. * @param isTrace ????trace????????true
  555. * @return
  556. *
  557. */
  558. public static function varDescribe(obj:*,isTrace:Boolean=true):String
  559. {
  560. var str:String = "";
  561. if(obj is String){
  562. str="\""+obj+"\"";
  563. }else if(obj is Array){
  564. for(var j:Number=0;j<obj.length;j++){
  565. if (str == "")
  566. {
  567. str = "[";
  568. }
  569. else
  570. {
  571. str += ",";
  572. }
  573. str += varDescribe(obj[j],false);
  574. }
  575. str+="]";
  576. }else if(obj is Boolean){
  577. if(obj){
  578. str="true";
  579. }else{
  580. str="false";
  581. }
  582. }else if(obj==null){
  583. str="Null"
  584. }else if(obj is Number||obj is int||obj is uint){
  585. str=obj;
  586. }else{
  587. for (var i:String in obj)
  588. {
  589. if (str == "")
  590. {
  591. str = "{";
  592. }
  593. else
  594. {
  595. str += ",";
  596. }
  597. str += i + ":" + varDescribe(obj[i],false);
  598. }
  599. str+="}";
  600. }
  601. if(isTrace) trace(str);
  602. return str;
  603. }
  604. }
  605. }