code_junkie

Possible to use Flex Framework/Components without using MXML?

Nov 11th, 2011
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <custom:ApplicationClass xmlns:custom="components.*"/>
  3.  
  4. package components {
  5. import mx.core.Application;
  6. import mx.events.FlexEvent;
  7. import flash.events.MouseEvent;
  8. import mx.controls.Alert;
  9. import mx.controls.Button;
  10.  
  11. public class ApplicationClass extends Application {
  12. public function ApplicationClass () {
  13. addEventListener (FlexEvent.CREATION_COMPLETE, handleComplete);
  14. }
  15. private function handleComplete( event : FlexEvent ) : void {
  16. var button : Button = new Button();
  17. button.label = "My favorite button";
  18. button.styleName="halo"
  19. button.addEventListener(MouseEvent.CLICK, handleClick);
  20. addChild( button );
  21. }
  22. private function handleClick(e:MouseEvent):void {
  23. Alert.show("You clicked on the button!", "Clickity");
  24. }
  25. }
  26. }
  27.  
  28. <?xml version="1.0" encoding="utf-8"?>
  29. <local:MyApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:local="components.*" />
  30.  
  31. package components {
  32. import flash.events.MouseEvent;
  33. import mx.controls.Alert;
  34. import mx.events.FlexEvent;
  35. import spark.components.Application;
  36. import spark.components.Button;
  37.  
  38. public class MyApplication extends Application {
  39. public function MyApplication() {
  40. addEventListener(FlexEvent.CREATION_COMPLETE, creationHandler);
  41. }
  42. private function creationHandler(e:FlexEvent):void {
  43. var button : Button = new Button();
  44. button.label = "My favorite button";
  45. button.styleName="halo"
  46. button.addEventListener(MouseEvent.CLICK, handleClick);
  47. addElement( button );
  48. }
  49. private function handleClick(e:MouseEvent):void {
  50. Alert.show("You clicked it!", "Clickity!");
  51. }
  52. }
  53. }
  54.  
  55. <?xml version="1.0" encoding="utf-8"?>
  56. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onCreationComplete()">
  57. <mx:Script source="Script.as" />
  58. </mx:Application>
  59.  
  60. import mx.controls.Button;
  61. import flash.events.MouseEvent;
  62. import mx.controls.Alert;
  63. import mx.core.Application;
  64.  
  65. private function onCreationComplete() : void {
  66. var button : Button = new Button();
  67. button.label = "Click me";
  68. button.addEventListener(MouseEvent.CLICK, function(e : MouseEvent) : void {
  69. Alert.show("Clicked");
  70. });
  71.  
  72. Application.application.addChild(button);
  73. }
  74.  
  75. package {
  76.  
  77. import mx.core.Application;
  78.  
  79.  
  80. public class MyFancyApplication extends Application {
  81.  
  82. // do whatever you want here
  83.  
  84. }
  85.  
  86. }
Add Comment
Please, Sign In to add comment