Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-02-2012, 04:01 PM   #1
Vraggeol
Registered User
 
Join Date: Apr 2012
Posts: 1
Default As3 -> as2

Hey all,

I hope this is the correct forum to post on. I've been programming in the as3 long ago, and now I have to program again in it. I know only the as3, but my project needs the as2. Can you, please, help me with translating it??? I tried it myself, but that's a nightmare and I really don't want to learn an another language. Also, sorry if there's some bugs, as I said, I didn't program long time
ActionScript Code:
import flash.display.Loader; import flash.net.URLRequest; import flash.events.Event; import flash.display.MovieClip; stop(); error.text = ""; PowerBar.mask = PowerBarMask; ///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// // Internal variables var symArray:Array = []; var symGraphics:Array = []; var onScreenSyms:Array = []; var power:int = 0; var endLoad:Boolean = false; var totalLoading:int = 0; var lastLoaded:int = 0; var err:String = ""; var IMAGE_LOOKUP_FOLDER:String = ""; var MAX_POWER:int = 0; var SYMBOL_XOFFSET:int = 0; var SYMBOL_YOFFSET:int = 0; var SYMBOL_SPACING:int = 0; var POWERBAR_HEIGHT:int = 0; ///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// // Used functions function Config(imageLookupFolder:String, maxPlayerPower:int, symbolXOffset:int, symbolYOffset:int,                 symbolSpacing:int, powerBarX:int, powerBarY:int, powerBarWidth:int, powerBarHeight:int):void {     IMAGE_LOOKUP_FOLDER = imageLookupFolder;     MAX_POWER = maxPlayerPower;     SYMBOL_XOFFSET = symbolXOffset;     SYMBOL_YOFFSET = symbolYOffset;     SYMBOL_SPACING = symbolSpacing;     POWERBAR_HEIGHT = powerBarHeight;         PowerBar.x = PowerBarMask.x = powerBarX;     PowerBar.y = PowerBarMask.y = powerBarY;     PowerBar.width = PowerBarMask.width = powerBarWidth;     PowerBar.height = powerBarHeight; } function LoadImage(imageName:String, imageFile:String, imageWidth:int, imageHeight:int) {     var i:int = symGraphics.length;     symGraphics[i] = [];     symGraphics[i][0] = new Loader();     symGraphics[i][0].contentLoaderInfo.addEventListener(Event.COMPLETE, function(event:Event){ OnLoad(++i); });     symGraphics[i][0].contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function(event:Event){ OnError(imageFile); });     symGraphics[i][0].load(new URLRequest(IMAGE_LOOKUP_FOLDER + imageFile));     symGraphics[i][1] = imageName;     symGraphics[i][2] = [imageWidth, imageHeight];         totalLoading++; } function EndLoad():void {     endLoad = true; } function ImagesLoaded():Boolean {     trace(endLoad, totalLoading, lastLoaded);     return (endLoad && lastLoaded == totalLoading); } function AddSymbol(symName:String):void {     if(!(endLoad && lastLoaded == totalLoading))     {         DispatchError("Images weren't loaded already.");         return;     }         symArray[symArray.length] = symName;     Redraw(); } function ResetSymbols():void {     symArray = [];     Redraw(); } function AddPower(powerSize:int):void {     power += powerSize;         if(power >= MAX_POWER)         power = MAX_POWER;     else if(power <= 0)         power = 0;         Redraw(); } ///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// // Internal functions /*/Testing>>// Config("C:/!/!! Flash Images/", 200, 300, 900, 30, 1700, 900, 30, 500); LoadImage("sun", "sun.jpg", 60, 60); LoadImage("space", "space.jpg", 60, 60); LoadImage("wind", "wind.jpg", 60, 60); LoadImage("earth", "earth.jpg", 60, 60); LoadImage("fire", "fire.jpg", 80, 80); LoadImage("ball", "ball.jpg", 80, 80); EndLoad(); var checkin:uint = setInterval(function(){             if(ImagesLoaded()){ clearInterval(checkin); setInterval(fnc, 1000);function fnc(){AddSymbol("sun"); AddPower(20);} AddSymbol("sun"); AddSymbol("sun"); AddSymbol("ball"); AddSymbol("earth"); setTimeout(function(){ ResetSymbols(); AddSymbol("fire"); AddSymbol("fire"); }, 5000);             }}, 20); //<<Testing/*/ function Redraw():void {        var currX:int = SYMBOL_XOFFSET;     var sym:Array = [];     var i:int = 0;         for(i = 0; i < onScreenSyms.length; i++)     {         removeChild(onScreenSyms[i]);         onScreenSyms[i] = undefined;     }     onScreenSyms = [];         for(i = 0; i < symArray.length; i++)     {         sym = GetSymbol(symArray[i]);         if(CheckError()) return;                 onScreenSyms[i] = sym[0];         onScreenSyms[i].width = sym[1][0];         onScreenSyms[i].height = sym[1][1];         onScreenSyms[i].x = currX;         onScreenSyms[i].y = SYMBOL_YOFFSET;                 addChild(onScreenSyms[i]);                 currX += SYMBOL_SPACING + sym[1][0];     }         PowerBarMask.height = (power == 0)? 0 : (power / MAX_POWER) * POWERBAR_HEIGHT; } function GetSymbol(symName:String):Array {     for(var i:int = 0; i < symGraphics.length; i++)     {         if(symGraphics[i][1] == symName)         {             var bmp:Bitmap = new Bitmap(symGraphics[i][0].content.bitmapData);             return [bmp, [symGraphics[i][2][0], symGraphics[i][2][1]]];         }     }     DispatchError("Requested symbol wasn't found.");     return []; } function CheckError():Boolean {     if(err != "")     {         return true;     }     return false; } function DispatchError(errString:String):void {     error.appendText(errString + "\n");     fscommand("error", errString); } function OnLoad(i:int):void {     if(i > lastLoaded)         lastLoaded = i; } function OnError(name:String):void {     DispatchError(name + " wasn't found."); }

EDIT:
'error' is an error textfield,
'PowerBar' and 'PowerBarMask' are two movieclips for animating power
Really, thank you all. I'll very appreciate all help.

Last edited by Vraggeol; 04-02-2012 at 04:04 PM. Reason: Note
Vraggeol is offline   Reply With Quote
Old 04-02-2012, 05:01 PM   #2
abeall
Senior Member
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,812
Send a message via AIM to abeall
Default

Are you asking for someone to do this for you? You might try posting on a job board, then.

AS2 is not really that different than AS3. The main differences I can spot in your code:

MovieClipLoader was used instead of the Loader class.

Use "Void" instead of "void"

Use Number instead of int

Use setMask instead of the mask property
__________________
Aaron Beall | Flash portfolio | Fireworks extensions | Twitter
abeall is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:06 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.