PageRenderTime 35ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/cutload/CutLoad/Base.as

http://cutload.googlecode.com/
ActionScript | 453 lines | 222 code | 5 blank | 226 comment | 12 complexity | 37a9e3fa9514776b2048648f003b7b95 MD5 | raw file
  1. package CutLoad
  2. {
  3. import CutLoad.cookies.Fun;
  4. import CutLoad.transitions.ITransition;
  5. import CutLoad.transitions.SpringMove;
  6. import CutLoad.transitions.TransitionsData;
  7. import flash.display.BitmapData;
  8. import flash.display.DisplayObject;
  9. import flash.display.Graphics;
  10. import flash.display.MovieClip;
  11. import flash.display.Sprite;
  12. import flash.geom.Point;
  13. import flash.geom.Rectangle;
  14. import flash.system.ApplicationDomain;
  15. /**
  16. * ??, ???Sprite?????,??cutload?????????????????cutload?????????????????????????cutload????????????
  17. * @author smallerbird mail:smallerbird@gmail.com site:www.mkigm.com QQ?:49983196
  18. *
  19. */
  20. public class Base extends Sprite implements IBase
  21. {
  22. /**
  23. *????????x
  24. */
  25. protected var LastX:Number=0
  26. /**
  27. *????????y
  28. */
  29. protected var LastY:Number=0;
  30. /**
  31. * ??????
  32. */
  33. protected var _objOtherInfo:Object=new Object();
  34. //??
  35. protected var transitions_movexy:ITransition;
  36. /**
  37. * ????????Base,????????Base,?????????
  38. * @param displayObj
  39. * @return
  40. *
  41. */
  42. public static function getBase(displayObj:DisplayObject):Base{
  43. var baseTem:Base=new Base();
  44. baseTem.addChild(displayObj);
  45. return baseTem;
  46. }
  47. /**
  48. * ???????????? ???,?????????
  49. * @param p_name
  50. * @return
  51. *
  52. */
  53. public static function getStrClassObject(p_name : String,applicationDomain:ApplicationDomain=null):Object
  54. {
  55. try
  56. {
  57. if(applicationDomain==null) applicationDomain=ApplicationDomain.currentDomain
  58. var myclass:Class=applicationDomain.getDefinition(p_name) as Class;
  59. return new myclass();
  60. }
  61. catch (p_e : ReferenceError)
  62. {
  63. throw new Error("?? " + p_name + " ???");
  64. return null;
  65. }
  66. return null;
  67. }
  68. /**
  69. * ???????????MovieClip??? ,????Base
  70. * @param p_name
  71. * @return
  72. *
  73. */
  74. public static function getStrClassMc(p_name : String):Base{
  75. return Base.getBase(getMcFromStrClass(p_name));
  76. }
  77. /**
  78. * ???????????MovieClip???
  79. * @return
  80. *
  81. */
  82. public static function getMcFromStrClass(p_name:String):MovieClip{
  83. var obj:Object=getStrClassObject(p_name);
  84. return obj as MovieClip;
  85. }
  86. /**
  87. * ??class
  88. * @param p_name
  89. * @return
  90. *
  91. */
  92. public static function getStrClass(p_name : String):Class
  93. {
  94. try
  95. {
  96. var myclass:Class=ApplicationDomain.currentDomain.getDefinition(p_name) as Class;
  97. return myclass;
  98. }
  99. catch (p_e : ReferenceError)
  100. {
  101. throw new Error("?? " + p_name + " ???");
  102. return null;
  103. }
  104. return null;
  105. }
  106. /**
  107. * ???????MovieClip??
  108. * @param linkName
  109. * @return
  110. *
  111. */
  112. public static function attachMovie(linkName:String):MovieClip{
  113. var mc:MovieClip=Base.getStrClassObject(linkName) as MovieClip;
  114. return mc
  115. }
  116. /**
  117. * ???????BitmapData??
  118. * @param linkName
  119. * @return
  120. *
  121. */
  122. public static function attachBitmap(linkName:String):BitmapData{
  123. var mc:BitmapData=Base.getStrClassObject(linkName) as BitmapData;
  124. return mc
  125. }
  126. /**
  127. * ????????BitmapData????????
  128. * @return
  129. *
  130. */
  131. public function photoMe():BitmapData{
  132. var img:BitmapData=new BitmapData(this.getShowWidth(),this.getShowHeight(),true,0xffffff);
  133. img.draw(this);
  134. return img;
  135. }
  136. /**
  137. * ????
  138. *
  139. */
  140. public function killMe():void{
  141. if(this.parent!=null) this.parent.removeChild(this);
  142. }
  143. /**
  144. * ?addChilde????????????????????????????????????????????????????????? addChildExpand(??1).addChildExpand(??2).addChildExpand(??3)
  145. * @param child
  146. * @param xx ???-10000 ?????
  147. * @param yy
  148. * @return
  149. *
  150. */
  151. public function addChildExpand(child:DisplayObject,xx:Number=-10000,yy:Number=-10000):Base{
  152. this.addChild(child);
  153. if(xx!=-10000) child.x=xx;
  154. if(yy!=-10000) child.y=yy;
  155. return this;
  156. }
  157. /**
  158. * ????????,????????????????????????????????????????appendOtherInfo
  159. * @param obj
  160. *
  161. */
  162. public function setOtherInfo(obj:Object):void{
  163. _objOtherInfo=obj;
  164. }
  165. /**
  166. * ???????????
  167. *
  168. */
  169. public function appendOtherInfo(obj:Object):void{
  170. Fun.appendObj(obj,_objOtherInfo);
  171. }
  172. /**
  173. * ???????? ? getOtherInfo()????
  174. * @return
  175. *
  176. */
  177. public function get objOtherInfo():Object{
  178. return _objOtherInfo;
  179. }
  180. /**
  181. * ????????
  182. * @return
  183. *
  184. */
  185. public function getOtherInfo():Object{
  186. return _objOtherInfo;
  187. }
  188. /**
  189. * ????
  190. * @param x
  191. * @param y
  192. * @param parent ??????????????null
  193. * @param transitions ????
  194. *
  195. */
  196. public function setXY(x:Number,y:Number,myParent:Sprite=null,transitions:ITransition=null):void
  197. {
  198. //
  199. setLastXY(this.x,this.y)
  200. //
  201. //????
  202. //????????
  203. if(transitions_movexy!=null) transitions_movexy.stop();
  204. //??????
  205. if(transitions!=null){
  206. var tdata:TransitionsData=new TransitionsData();
  207. tdata.target=this;
  208. tdata.x=x;
  209. tdata.y=y;
  210. transitions_movexy=transitions.clone(tdata);
  211. transitions_movexy.start(tdata);
  212. }else{
  213. this.x=x;
  214. this.y=y;
  215. }
  216. if(myParent!=null) this.show(myParent);
  217. }
  218. /**
  219. * ????
  220. * @param point
  221. * @param myParent
  222. *
  223. */
  224. public function setXYPoint(point:Point,myParent:Sprite=null):void{
  225. setXY(point.x,point.y,myParent);
  226. }
  227. /**
  228. * ????????????
  229. * @param t 0??,1??,2??,3??,4??,5??,6??,7??,8??
  230. * @param base ???????????????
  231. * @return
  232. *
  233. */
  234. public function followMe(t:Number,base:Base=null):Point{
  235. var atPoint:Point;
  236. switch(t){
  237. case 1:
  238. atPoint=new Point(x,y);
  239. break;
  240. case 2:
  241. atPoint=this.getXYUpCenter();
  242. break;
  243. case 3:
  244. atPoint=this.getXYRightUp();
  245. break;
  246. case 4:
  247. atPoint=this.getXYRightCenter();
  248. break;
  249. case 5:
  250. atPoint=this.getXYRightDown();
  251. break;
  252. case 6:
  253. atPoint=this.getXYDownCenter()
  254. break;
  255. case 7:
  256. atPoint=this.getXYLeftDown();
  257. break;
  258. case 8:
  259. atPoint=this.getXYLeftCenter();
  260. break;
  261. default:
  262. atPoint=this.getXYCenter();
  263. break;
  264. }
  265. if(base!=null) base.setXYPoint(atPoint);
  266. return atPoint;
  267. }
  268. /**
  269. * ????????????????
  270. * @param xx
  271. * @param yy
  272. * @return
  273. *
  274. */
  275. public function compareLastXY(xx:Number,yy:Number):Boolean{
  276. if(xx==this.LastX&&yy==this.LastY) return true;
  277. return false;
  278. }
  279. /**
  280. * ???????????
  281. *
  282. */
  283. public function resetLastXY():void{
  284. this.setXY(this.LastX,this.LastY);
  285. }
  286. /**
  287. * ??lastX lastY
  288. * @param xx
  289. * @param yy
  290. *
  291. */
  292. public function setLastXY(xx:Number,yy:Number):void{
  293. this.LastX=xx;
  294. this.LastY=yy;
  295. }
  296. /**
  297. * ????
  298. * @param w ?
  299. * @param h ?
  300. *
  301. */
  302. public function setWH(w:Number=0,h:Number=0):void{
  303. if(w!=0) this.width=w;
  304. if(h!=0) this.height=h;
  305. }
  306. /**
  307. * ????,?????????IBase???getShowWidth() ? getShowHeight() ????
  308. * @param base
  309. *
  310. */
  311. public function setWHFormBase(base:IBase):void{
  312. setWH(base.getShowWidth(),base.getShowHeight())
  313. }
  314. /**
  315. * ???????????
  316. * @param a
  317. *
  318. */
  319. public function setAlpha(a:Number):void{
  320. this.alpha=a;
  321. }
  322. /**
  323. * ??????????
  324. * @param parent ??????
  325. *
  326. */
  327. public function show(parent:Sprite):void{
  328. if(this.parent!=null){
  329. trace("??:Base.show()???parent!=null!!");
  330. return;
  331. }
  332. parent.addChild(this);
  333. }
  334. /**
  335. * ???????
  336. * @return
  337. *
  338. */
  339. public function getShowWidth():Number
  340. {
  341. return this.width;
  342. }
  343. /**
  344. * ???????
  345. * @return
  346. *
  347. */
  348. public function getShowHeight():Number
  349. {
  350. return this.height;
  351. }
  352. /**
  353. * ????????
  354. * @return
  355. *
  356. */
  357. public function getXYRightUp():Point{
  358. return new Point(x+getShowWidth(),y);
  359. }
  360. /**
  361. * ????????
  362. * @return ??:{x:xx,y:yy}
  363. *
  364. */
  365. public function getXYRightDown():Point{
  366. return new Point(x+getShowWidth(),y+getShowHeight());
  367. }
  368. /**
  369. * ????????
  370. * @return ??:{x:xx,y:yy}
  371. *
  372. */
  373. public function getXYLeftDown():Point{
  374. return new Point(x,y+getShowHeight());
  375. }
  376. /**
  377. * ?????
  378. * @return
  379. *
  380. */
  381. public function getXYUpCenter():Point{
  382. return new Point(x+getShowWidth()/2,y);
  383. }
  384. /**
  385. * ?????
  386. * @return
  387. *
  388. */
  389. public function getXYRightCenter():Point{
  390. return new Point(x+getShowWidth(),y+this.getShowHeight()/2);
  391. }
  392. /**
  393. * ?????
  394. * @return
  395. *
  396. */
  397. public function getXYDownCenter():Point{
  398. return new Point(x+getShowWidth()/2,y+this.getShowHeight());
  399. }
  400. /**
  401. * ?????
  402. * @return
  403. *
  404. */
  405. public function getXYLeftCenter():Point{
  406. return new Point(x,y+this.getShowHeight()/2);
  407. }
  408. /**
  409. * ?????
  410. * @return
  411. *
  412. */
  413. public function getXYCenter():Point{
  414. return new Point(x+getShowWidth()/2,y+this.getShowHeight()/2);
  415. }
  416. /**
  417. * ?point??????????
  418. * @param point
  419. * @param myParent
  420. *
  421. */
  422. public function setPosition(point:Point,myParent:Sprite=null):void{
  423. this.setXY(point.x,point.y,myParent);
  424. }
  425. /**
  426. * ????Point??
  427. * @return
  428. *
  429. */
  430. public function getPosition():Point{
  431. return new Point(x,y);
  432. }
  433. /**
  434. * ????? Rectangle??
  435. * @return
  436. *
  437. */
  438. public function getRectInfo():Rectangle{
  439. return new Rectangle(x,y,this.getShowWidth(),this.getShowHeight()) ;
  440. }
  441. /**
  442. * ????
  443. *
  444. */
  445. public function printInfon():void{
  446. }
  447. }
  448. }