Hi guys,
I have built a calculator in actionscript3 in flash. However, I now need to use it in a flex app and was thinking the best way to do this would be to create an actionscript class in my flex project.
I have no idea how to do this though. In the actionscript I am calling on the instances which are obviously not available in the flex class. I really cant get my head around classes in flex so any help would really go along way to getting me there.
I have a movieclip called calculator and within that a number of buttons that have the functions on them. Can I import just calculator into flex or do I have to import each button separately?
attactched is the actionscript 3 actions layer that I have in flash.
Attach Code
calculator_mc.calc_Btn.addEventListener(MouseEvent.CLICK, calcClick);
calculator_mc.reset_Btn.addEventListener(MouseEvent.CLICK, resetClick);
calculator_mc.zero_Btn.addEventListener(MouseEvent.CLICK, zeroClick);
calculator_mc.one_Btn.addEventListener(MouseEvent.CLICK, oneClick);
calculator_mc.two_Btn.addEventListener(MouseEvent.CLICK, twoClick);
calculator_mc.three_Btn.addEventListener(MouseEvent.CLICK, threeClick);
calculator_mc.four_Btn.addEventListener(MouseEvent.CLICK, fourClick);
calculator_mc.five_Btn.addEventListener(MouseEvent.CLICK, fiveClick);
calculator_mc.six_Btn.addEventListener(MouseEvent.CLICK, sixClick);
calculator_mc.seven_Btn.addEventListener(MouseEvent.CLICK, sevenClick);
calculator_mc.eight_Btn.addEventListener(MouseEvent.CLICK, eightClick);
calculator_mc.nine_Btn.addEventListener(MouseEvent.CLICK, nineClick);
var mileage:String = '';
function zeroClick(event:MouseEvent):void {
mileage = mileage + '0';
calculator_mc.result_Txt.text = mileage;
trace(mileage);
}
function oneClick(event:MouseEvent):void {
mileage = mileage + '1';
calculator_mc.result_Txt.text = mileage;
}
function twoClick(event:MouseEvent):void {
mileage = mileage + '2';
calculator_mc.result_Txt.text = mileage;
}
function threeClick(event:MouseEvent):void {
mileage = mileage + '3';
calculator_mc.result_Txt.text = mileage;
}
function fourClick(event:MouseEvent):void {
mileage = mileage + '4';
calculator_mc.result_Txt.text = mileage;
}
function fiveClick(event:MouseEvent):void {
mileage = mileage + '5';
calculator_mc.result_Txt.text = mileage;
}
function sixClick(event:MouseEvent):void {
mileage = mileage + '6';
calculator_mc.result_Txt.text = mileage;
}
function sevenClick(event:MouseEvent):void {
mileage = mileage + '7';
calculator_mc.result_Txt.text = mileage;
}
function eightClick(event:MouseEvent):void {
mileage = mileage + '8';
calculator_mc.result_Txt.text = mileage;
}
function nineClick(event:MouseEvent):void {
mileage = mileage + '9';
calculator_mc.result_Txt.text = mileage;
}
var result_Value:Number;
function calcClick(event:MouseEvent):void {
result_Value = parseInt(mileage) + 5;
calculator_mc.result_Txt.text = 'Saving: £' + result_Value.toString();
if (mileage == '') {
calculator_mc.result_Txt.text = '0';
}
}
function resetClick(event:MouseEvent):void {
calculator_mc.result_Txt.text = 'Enter your milage..';
mileage = '';
}
Page 1 of 1
actionscript 3 to flex
#2
Posted 27 August 2008 - 08:50 PM
You will need this:
http://livedocs.adobe.com/flex/3/html/
http://actionscript.org
You should make a package containing the Calculator class. It looks like all the classes you are calling are available in Flex 3. If you troubles are about getting the UI to hook up with the AS3.0 I hear you. Flex isn't really the best for UI layout but there are ways to do it. I think the Grid class would be a good place to start.
"A Grid container lets you arrange children as rows and columns of cells, similar to an HTML table. The Grid container contains one or more rows, and each row can contain one or more cells, or items. You use the following tags to define a Grid control"
http://livedocs.adobe.com/flex/3/html/
http://actionscript.org
You should make a package containing the Calculator class. It looks like all the classes you are calling are available in Flex 3. If you troubles are about getting the UI to hook up with the AS3.0 I hear you. Flex isn't really the best for UI layout but there are ways to do it. I think the Grid class would be a good place to start.
"A Grid container lets you arrange children as rows and columns of cells, similar to an HTML table. The Grid container contains one or more rows, and each row can contain one or more cells, or items. You use the following tags to define a Grid control"
- ← Flash Movie background not rendering in Firefox 2 Mac
- Flash, Actionscript & RIA
- Widget Scrolling →
Share this topic:
Page 1 of 1
Help















