# uSING ACTIONSCRIPT3 IN FLEX PROJECT

**URL:** <https://forum.kirupa.com/t/using-actionscript3-in-flex-project/256019>\
**Category:** flash\
**Created:** [March 29, 2008, 11:37am UTC](https://forum.kirupa.com/t/using-actionscript3-in-flex-project/256019 "2008-03-29T11:37:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![amitabharya23](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@amitabharya23](https://forum.kirupa.com/u/amitabharya23)\
**Post date:** [March 29, 2008, 11:37am UTC](https://forum.kirupa.com/t/using-actionscript3-in-flex-project/256019/1 "2008-03-29T11:37:38Z")

</div>

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]](http://www.adobe.com/2006/mxml%5B/COLOR%5D%5B/SIZE%5D%5BSIZE=2%5D)" 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](https://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]
