Jump to content
Search Community

How to modify the AS2 code to AS3?

learner_7n test
Moderator Tag

Recommended Posts

Hi,

 

I got an image gallery .Fla file which is working fine (AS2). But when I copied the same frames to My Project which is in AS3, it throws error (Migration issue).

 

How to modify it to AS3 so that it works with my project?

 

The Code is:

 

import gs.*; 
import gs.easing.*;

//////////////////////////////////////////////////////////////////
//                   Load XML
//////////////////////////////////////////////////////////////////

var xmlPath = "content.xml";
var photos_xml = new XML();
photos_xml.ignoreWhite = true;
var imageList:Array = new Array();
photos_xml.onLoad = function(success) {
if (success) { // ----------- load successful
	// ----------- convert XML content to an array
	imageList = photos_xml.firstChild.childNodes;
	// ----------- Do some action once xml is loaded
	loadImage();
	// ----------- Do some action once xml is loaded
} else {
	// ----------- problem loading, check path
	trace("Error loading photos_xml");
}
};
//////////////////////////////////////////////////////////////////
//                   Load Images
//////////////////////////////////////////////////////////////////

var currentImage:Number = 0;
var imageLoader:MovieClipLoader = new MovieClipLoader();
var loadListener:Object = new Object();

imageLoader.addListener(loadListener);

loadListener.onLoadInit = function(target_mc:MovieClip, httpStatus:Number):Void {
TweenLite.to(shell_mc.background_mc, 0.25, {_width:target_mc._width + 20, _height:target_mc._height + 20, ease:Quad.easeOut});
TweenLite.to(shell_mc.border_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
TweenLite.to(shell_mc.mask_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});

// center content
var clipXTarg = Math.round((Stage.width/2)-((target_mc._width+20)/2));
var clipYTarg = Math.round((Stage.height/2)-((target_mc._height+20)/2));
TweenLite.to(shell_mc, 0.25, {_x:clipXTarg, _y:clipYTarg, ease:Quad.easeOut});

// find previous image
if(currentImage == 0){
	var prevImgNum = imageList.length -1;
}else{
	var prevImgNum = currentImage - 1;
}
var prevImg = shell_mc.pics_mc["pic"+prevImgNum];
TweenLite.to(prevImg, 0.25, {autoAlpha:0, onComplete:removePrevious});
}

loadListener.onLoadComplete = function(target_mc:MovieClip):Void {
TweenLite.to(target_mc, 0.25, {autoAlpha:100, delay:0.25});
setTimer();
}

//////////////////////////////////////////////////////////////////
//                   Functions List
//////////////////////////////////////////////////////////////////

function setTimer(){
timer = setInterval(loadImage, 5000);
}

function removePrevious(){
if(prevImg != undefined){
	removeMovieClip(prevImg);
}

// increment the current image
if(currentImage < imageList.length -1){
	currentImage = currentImage + 1;
}else{
	currentImage = 0;
}
}


function loadImage(){
var loadURL = imageList[currentImage].attributes.imgurl;
var targetClip = shell_mc.pics_mc.createEmptyMovieClip("pic"+currentImage,shell_mc.pics_mc.getNextHighestDepth());
targetClip._alpha = 0;
clearInterval(timer);

// load the new image
imageLoader.loadClip(loadURL,targetClip);
}


//////////////////////////////////////////////////////////////////
//                   On First Load
//////////////////////////////////////////////////////////////////
photos_xml.load(xmlPath);
stop();

 

Thanks for any help provided.

Link to comment
Share on other sites

Migrating from AS2 to AS3 can be a difficult transition, it took me a few months of diligent practice.

 

I don't think anyone is going to do a line-by-line conversion for you as it would take a bit of time and it is not the purpose of this forum.

For the most part you would have to rebuild the as2 code from scratch.

 

This migration guide has a lot of great tips and source files: http://www.mandalatv.net/fcny/

 

I would suggest you write down exactly the functionality that you need and then try to build it one step at a time... for example:

 

1:load xml

2:load the first image

3:when image loads, fade it in

4:set a timer

5:load next image

...

 

GreenSock has many tools in LoaderMax to make this much easier than using the native AS3 Loaders, in fact the documentation includes source code that illustrates loading an xml file and all the assets that it contains information on.

 

http://www.greensock.com/as/docs/tween/ ... oader.html

 

it will take some reading and experimenting but this is a great exercise to aid in your AS3 development.

 

I am going to be doing a series of tutorials on LoaderMax very soon and will provide lots of "starter" files. I may just create a version that loops through images on a timer. If I do, I will be sure to update this post.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...