PageRenderTime 83ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/v0.8.0/Test_Red2D_V0.8.0/src/ex/Test14_DisplayContainer_Mathod.as

http://red2d-agal2d.googlecode.com/
ActionScript | 318 lines | 231 code | 45 blank | 42 comment | 14 complexity | af47ac83653fe78992d43435d37e4e8c MD5 | raw file
  1. package ex
  2. {
  3. /**
  4. * by Paik seonki / redcamel
  5. * webseon@hanmail.net
  6. */
  7. import com.bit101.components.Label;
  8. import com.bit101.components.PushButton;
  9. import com.bit101.components.Style;
  10. import com.bit101.components.Text;
  11. import com.greensock.TweenLite;
  12. import com.greensock.easing.Elastic;
  13. import flash.display.Sprite;
  14. import flash.display.StageDisplayState;
  15. import flash.events.Event;
  16. import flash.events.FocusEvent;
  17. import flash.events.KeyboardEvent;
  18. import flash.net.URLRequest;
  19. import flash.net.navigateToURL;
  20. import red2D.display.Red_Sprite;
  21. import red2D.material.BitmapMaterial;
  22. import red2D.system.Red_Scene;
  23. import red2D.text.Red_TextField;
  24. /**
  25. * 14 Container - ???? ??? ???
  26. * @author redcamel
  27. *
  28. */
  29. public class Test14_DisplayContainer_Mathod extends Red_Scene
  30. {
  31. // ?? ???? ?? ???
  32. [Embed( source = "./resource/flower.png" )]
  33. private static var MapTest1:Class;
  34. // ?? ???? ?? ???
  35. [Embed( source = "./resource/testImg2.jpg" )]
  36. private static var MapTest2:Class;
  37. // ?? ???? ?? ???
  38. private var gui:Sprite
  39. private var removeBt2Txt:Text;
  40. private var removeBt2Txt2:Text;
  41. private var getChildByNameTxt:Text;
  42. private var getChildAtTxt:Text;
  43. private var setChildIndexTxt:Text;
  44. private var swapChildrenAtTxt:Text;
  45. private var swapChildrenAtTxt2:Text;
  46. private var getChildIndexTxt:Text;
  47. private var material1:BitmapMaterial
  48. private var material2:BitmapMaterial
  49. public function Test14_DisplayContainer_Mathod()
  50. {
  51. }
  52. /**
  53. * ?? ????? setDesign???? ????? ?? ?????.
  54. *
  55. */
  56. public override function setDesign():void{
  57. material1 = new BitmapMaterial(new MapTest1().bitmapData)
  58. material2 = new BitmapMaterial(new MapTest2().bitmapData)
  59. setUI()
  60. stage.addEventListener(KeyboardEvent.KEY_DOWN, HD_key)
  61. }
  62. /**
  63. * Red_SceneV0.8 ??? ? updatea? ?????? ??? ??????.
  64. * ??? stage? ????? ???? ?? ??? ??? ??? ???????.
  65. * update???? ??????? ??? ??????? ???? ???? ??? ? ????.
  66. *
  67. */
  68. public override function update():void
  69. {
  70. if(childNum!=0){
  71. for (var i:Number =0 ; i<childNum; i++){
  72. var target:Red_Sprite = children[i]
  73. target.x += ((stage.stageWidth/2+Math.sin(360/childNum*i*Math.PI/180)*(stage.stageHeight-100)/2)-children[i].x)*0.3
  74. target.y += ((stage.stageHeight/2+Math.cos(360/childNum*i*Math.PI/180)*(stage.stageHeight-100)/2)-children[i].y)*0.3
  75. }
  76. }
  77. }
  78. protected function HD_key(e:KeyboardEvent):void{
  79. if(e.keyCode ==70){
  80. stage.displayState = StageDisplayState.FULL_SCREEN
  81. }
  82. }
  83. private function setUI():void
  84. {
  85. gui = new Sprite()
  86. gui.x = 5
  87. gui.y = 5
  88. Style.setStyle(Style.DARK);
  89. stage.addChild(gui)
  90. var guiTitle:Label = new Label(gui,0,0,"Red2D Test\nContainer Method")
  91. ///////////////////////////////////////////////////////////////////////////////////////////////////
  92. var addChildBt:PushButton = new PushButton(gui,0,40,"addChild", HD_addChild)
  93. new Label(gui,110,40,"Add Red_Sprite and addChild")
  94. ///////////////////////////////////////////////////////////////////////////////////////////////////
  95. var addChildAtBt:PushButton = new PushButton(gui,0,60,"addChildAt", HD_addChildAt)
  96. ///////////////////////////////////////////////////////////////////////////////////////////////////
  97. var removeBt:PushButton = new PushButton(gui,0,90,"removeChild", HD_removeChild)
  98. new Label(gui,110,90,"RemoveChild Red_Sprite in DisplayList")
  99. ///////////////////////////////////////////////////////////////////////////////////////////////////
  100. var removeBt2:PushButton = new PushButton(gui,0,110,"removeChildAt", HD_removeChildAt)
  101. removeBt2Txt = new Text(gui,110,110,"0")
  102. removeBt2Txt.width = 30
  103. removeBt2Txt.height = 20
  104. removeBt2Txt2 = new Text(gui,110,60,"0")
  105. removeBt2Txt2.width = 30
  106. removeBt2Txt2.height = 20
  107. ///////////////////////////////////////////////////////////////////////////////////////////////////
  108. var getChildByName:PushButton = new PushButton(gui,0,140,"getChildByName", HD_getChildByName)
  109. getChildByNameTxt = new Text(gui,110,140,"insert child Name")
  110. getChildByNameTxt.width = 250
  111. getChildByNameTxt.height = 20
  112. getChildByNameTxt.addEventListener(FocusEvent.FOCUS_IN, resetTxt)
  113. ///////////////////////////////////////////////////////////////////////////////////////////////////
  114. var getChildAt:PushButton = new PushButton(gui,0,160,"getChildAt", HD_getChildAt)
  115. getChildAtTxt = new Text(gui,110,160,"insert child IndexNumber")
  116. getChildAtTxt.width = 250
  117. getChildAtTxt.height = 20
  118. getChildAtTxt.addEventListener(FocusEvent.FOCUS_IN, resetTxt)
  119. ///////////////////////////////////////////////////////////////////////////////////////////////////
  120. var getChildIndex:PushButton = new PushButton(gui,0,180,"getChildIndex", HD_getChildIndex)
  121. getChildIndexTxt = new Text(gui,110,180,"Insert target name!")
  122. getChildIndexTxt.width = 250
  123. getChildIndexTxt.height = 20
  124. getChildIndexTxt.addEventListener(FocusEvent.FOCUS_IN, resetTxt)
  125. ///////////////////////////////////////////////////////////////////////////////////////////////////
  126. var setChildIndex:PushButton = new PushButton(gui,0,210,"lastChild-setChildIndex", HD_setChildIndex)
  127. setChildIndexTxt = new Text(gui,110,210,"0")
  128. setChildIndexTxt.width = 20
  129. setChildIndexTxt.height = 20
  130. ///////////////////////////////////////////////////////////////////////////////////////////////////
  131. var swapChildrenAt:PushButton = new PushButton(gui,0,230,"swapChildrenAt", HD_swapChildrenAt)
  132. swapChildrenAtTxt = new Text(gui,110,230,"0")
  133. swapChildrenAtTxt.width = 20
  134. swapChildrenAtTxt.height = 20
  135. swapChildrenAtTxt2 = new Text(gui,130,230,"1")
  136. swapChildrenAtTxt2.width = 20
  137. swapChildrenAtTxt2.height = 20
  138. ///////////////////////////////////////////////////////////////////////////////////////////////////
  139. var swapChildren:PushButton = new PushButton(gui,0,250,"swapChildren", HD_swapChildren)
  140. new Label(gui,110,250,"firstChild & lastChild SwapDepths!!!!")
  141. ///////////////////////////////////////////////////////////////////////////////////////////////////
  142. var removeChildAll:PushButton = new PushButton(gui,0,280,"removeChildAll", HD_removeChildAll)
  143. new Label(gui,110,280,"remove all child in DisplayList!!")
  144. }
  145. /*************************************************************************/
  146. /** ????**/
  147. /*************************************************************************/
  148. private function HD_removeChildAll($e:Event=null):void
  149. {
  150. removeChildAll()
  151. }
  152. protected function resetTxt( $e:FocusEvent ):void
  153. {
  154. $e.currentTarget.text = ""
  155. }
  156. private function HD_getChildIndex($e:Event=null):void
  157. {
  158. if(childNum==0){
  159. navigateToURL(new URLRequest("javascript:alert('??? ??? ????')"),"_self")
  160. return
  161. }
  162. var target:Red_Sprite = getChildByName(getChildIndexTxt.text)
  163. if(target!=null){
  164. getChildIndexTxt.text = "success search! indexNumber is : " + String(getChildIndex(target))
  165. TweenLite.to( target , 2,{rotation:Math.random()*360, ease:Elastic.easeOut })
  166. }else{
  167. getChildIndexTxt.text = "fail search, Insert another target name!"
  168. }
  169. }
  170. private function HD_swapChildren($e:Event=null):void
  171. {
  172. if(childNum==0){
  173. navigateToURL(new URLRequest("javascript:alert('??? ??? ????')"),"_self")
  174. return
  175. }
  176. swapChildren(children[0], children[childNum-1])
  177. }
  178. private function HD_swapChildrenAt($e:Event=null):void
  179. {
  180. if(childNum==0){
  181. navigateToURL(new URLRequest("javascript:alert('??? ??? ????')"),"_self")
  182. return
  183. }
  184. swapChildrenAt(Number(swapChildrenAtTxt.text), Number(swapChildrenAtTxt2.text))
  185. }
  186. private function HD_setChildIndex($e:Event=null):void
  187. {
  188. if(childNum==0){
  189. navigateToURL(new URLRequest("javascript:alert('??? ??? ????')"),"_self")
  190. return
  191. }
  192. setChildIndex( children[childNum-1], Number(setChildIndexTxt.text) )
  193. }
  194. private function HD_getChildAt($e:Event=null):void
  195. {
  196. var target:Red_Sprite = getChildAt(Number(getChildAtTxt.text))
  197. if(target!=null){
  198. getChildAtTxt.text ="success search : " + target.name
  199. TweenLite.to( target , 3,{rotation:Math.random()*360, ease:Elastic.easeOut })
  200. }else{
  201. getChildAtTxt.text = "fail search, Insert another target index!"
  202. }
  203. }
  204. private function HD_getChildByName($e:Event=null):void
  205. {
  206. var target:Red_Sprite = getChildByName(getChildByNameTxt.text)
  207. if(target!=null){
  208. getChildByNameTxt.text ="success search : " + target.name
  209. TweenLite.to( target , 3,{rotation:Math.random()*360, ease:Elastic.easeOut })
  210. }else{
  211. getChildByNameTxt.text = "fail search, Insert another target name!"
  212. }
  213. }
  214. private function HD_addChildAt($e:Event=null):void
  215. {
  216. var testBox:Red_Sprite = new Red_Sprite(100,100, stage.stageWidth/2, stage.stageHeight/2)
  217. addChildAt(testBox, Number(removeBt2Txt2.text))
  218. //????
  219. testBox.name = "test"+(childNum-1)
  220. //????
  221. testBox.material = material1
  222. var textInfo:Red_TextField = new Red_TextField()
  223. textInfo.text = testBox.name
  224. //textBox? Red_TextField??
  225. testBox.addChild(textInfo)
  226. textInfo.y= testBox.height/2+10
  227. resetAllText()
  228. }
  229. private function HD_removeChildAt($e:Event=null):void
  230. {
  231. if(childNum==0){
  232. navigateToURL(new URLRequest("javascript:alert('??? ??? ????')"),"_self")
  233. return
  234. }
  235. removeChildAt(Number(removeBt2Txt.text))
  236. resetAllText()
  237. }
  238. private function HD_removeChild($e:Event=null):void
  239. {
  240. if(childNum==0){
  241. navigateToURL(new URLRequest("javascript:alert('??? ??? ????')"),"_self")
  242. return
  243. }
  244. removeChild(children[childNum-1])
  245. resetAllText()
  246. }
  247. private function HD_addChild($e:Event=null):void
  248. {
  249. //trace($e.currentTarget)
  250. var testBox:Red_Sprite = new Red_Sprite(100,100, stage.stageWidth/2, stage.stageHeight/2)
  251. addChild(testBox)
  252. testBox.name = "test"+(childNum-1)
  253. //????
  254. testBox.material = material2
  255. var textInfo:Red_TextField = new Red_TextField()
  256. textInfo.text = testBox.name
  257. //textBox? Red_TextField??
  258. testBox.addChild(textInfo)
  259. textInfo.y= testBox.height/2+10
  260. resetAllText()
  261. }
  262. private function resetAllText():void
  263. {
  264. if(childNum!=0){
  265. for (var i:Number =0 ; i<childNum; i++){
  266. var target:Red_Sprite = children[i]
  267. var targetTextField:Red_TextField = target.getChildAt(0)as Red_TextField
  268. targetTextField.text = "this.name : "+target.name +"\nindexNum : "+i
  269. }
  270. }
  271. }
  272. }
  273. }