Hi,
I am trying to use actionscript 3 in flex project. I don’t want to code anything in flex file (mxml) except initialization of my first class. Also want to use flex components in actionscript.
I tried but its not working, any one can help me. I am writting the code for mxml file and AS3(actionscript 3) class file code below.
code:
[MXML file code](default application file)
[LEFT][SIZE=2]<?xml version=“1.0” encoding=“utf-8”?>[/SIZE][/LEFT]
[SIZE=2][COLOR=#0000ff]<mx:Application
[/COLOR][/SIZE][LEFT][SIZE=2]xmlns:mx="[/SIZE][SIZE=2][COLOR=#990000]http://www.adobe.com/2006/mxml[/COLOR][/SIZE][SIZE=2]" layout="[/SIZE][SIZE=2][COLOR=#990000]absolute[/COLOR][/SIZE][SIZE=2]" creationComplete=“onCreationComplete( event );”[/SIZE][SIZE=2][COLOR=#0000ff]>[/COLOR][/SIZE]
[LEFT][SIZE=2][COLOR=#006633]<mx:Script>[/COLOR][/SIZE][/LEFT]
[LEFT][SIZE=2]<![CDATA[[/SIZE]
[SIZE=2][COLOR=#0033ff]import[/COLOR][/SIZE][SIZE=2] mx.controls.Alert;[/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=#0033ff]import[/COLOR][/SIZE][SIZE=2] mx.events.FlexEvent;[/SIZE]
[SIZE=2][COLOR=#0033ff]import[/COLOR][/SIZE][SIZE=2] Classes.InitApp;[/SIZE]
[SIZE=2][COLOR=#0033ff]private[/COLOR][/SIZE]****[SIZE=2][COLOR=#339966]function[/COLOR][/SIZE][SIZE=2] onCreationComplete( event:FlexEvent ):[/SIZE][SIZE=2][COLOR=#0033ff]void[/COLOR][/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#6699cc]var[/COLOR][/SIZE][SIZE=2] myInitApp:InitApp = [/SIZE][SIZE=2][COLOR=#0033ff]new[/COLOR][/SIZE][SIZE=2] InitApp();[/SIZE]
[SIZE=2]mx.controls.Alert.show([/SIZE][SIZE=2][COLOR=#990000]“Alert1”[/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2][COLOR=#009900]//Alert.show(“adfka”);[/COLOR][/SIZE]
[SIZE=2][COLOR=#009900]// ActionScript from here onwards…[/COLOR][/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
[LEFT][SIZE=2]]]>[/SIZE]
[SIZE=2][COLOR=#006633]</mx:Script>[/COLOR][/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=#0000ff]</mx:Application>[/COLOR][/SIZE][/LEFT]
[Actionscript 3 class file code ]
[LEFT][SIZE=2][COLOR=#9900cc]package[/LEFT]
[/LEFT]
[/COLOR][/SIZE][LEFT][SIZE=2]Classes[/SIZE]
[LEFT][SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0033ff]import[/COLOR][/SIZE][SIZE=2] flash.display.Sprite;[/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=#0033ff]import[/COLOR][/SIZE][SIZE=2] mx.containers.Canvas;[/SIZE]
[SIZE=2][COLOR=#0033ff]import[/COLOR][/SIZE][SIZE=2] mx.containers.Panel;[/SIZE]
[SIZE=2][COLOR=#0033ff]import[/COLOR][/SIZE][SIZE=2] mx.controls.Button;[/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=#0033ff]public[/COLOR][/SIZE]****[SIZE=2][COLOR=#9900cc]class[/COLOR][/SIZE][SIZE=2] InitApp [/SIZE][SIZE=2][COLOR=#0033ff]extends[/COLOR][/SIZE][SIZE=2][COLOR=#009900]Canvas, [/COLOR][/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0033ff]public[/COLOR][/SIZE]****[SIZE=2][COLOR=#339966]function[/COLOR][/SIZE][SIZE=2] InitApp()[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#009900]super();[/COLOR][/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=#6699cc]var[/COLOR][/SIZE][SIZE=2] myBut:Button = [/SIZE][SIZE=2][COLOR=#0033ff]new[/COLOR][/SIZE][SIZE=2] Button();[/SIZE]
[SIZE=2]myBut.id = [/SIZE][SIZE=2][COLOR=#990000]“myB”[/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]myBut.label =[/SIZE][SIZE=2][COLOR=#990000]“aaaa”[/COLOR][/SIZE][SIZE=2];[/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=#6699cc]var[/COLOR][/SIZE][SIZE=2] myPp = [/SIZE][SIZE=2][COLOR=#0033ff]new[/COLOR][/SIZE][SIZE=2] Panel();[/SIZE]
[SIZE=2]myPp.id = [/SIZE][SIZE=2][COLOR=#990000]“myP”[/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]addChild(myPp);[/SIZE]
[SIZE=2]myPp.addChild(myBut);[/SIZE]
[SIZE=2]mx.controls.Alert.show([/SIZE][SIZE=2][COLOR=#990000]"Alert2 "[/COLOR][/SIZE][SIZE=2]+myBut[/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
[LEFT][SIZE=2]}[/SIZE][/LEFT]
[SIZE=2]}[/SIZE]
In case there is any confusion, please write back to me.
[/LEFT]