Solved

Convert AC2 to AC3 for me

Posted on 2010-11-12
2
1,273 Views
Last Modified: 2013-11-11
I was given this code from AS2, but how would it look like in AC3 is the question I am having... Someone please help as I am clueless with AS3.

var tnNr;
spacing = 10;
container._alpha = 0;
var curLength;
MovieClip.prototype.loadPic = function(pic, id) {
	info.text = "";
	this._alpha = 0;
	this.loadMovie(pic);
	temp = this._parent.createEmptyMovieClip("temp2", 998);
	temp.onEnterFrame = function() {
		var t = container.getBytesTotal(), l = container.getBytesLoaded();
		if (Math.round(l/t) == 1 && container._width != 0 && container._height != 0) {
			var w = container._width+spacing, h = container._height+spacing;
			border.resizeMe(w, h, id);
			delete this.onEnterFrame;
		}
	};
};
MovieClip.prototype.resizeMe = function(w, h, id) {
	var speed = 3;
	container._alpha = 0;
	this.onEnterFrame = function() {
		this._width += (w-this._width)/speed;
		this._height += (h-this._height)/speed;
		if (Math.abs(this._width-w)<1 && Math.abs(this._height-h)<1) {
			this._width = w;
			this._height = h;
			container._x = this._x-this._width/2+spacing/2;
			container._y = this._y-this._height/2+spacing/2;
			info._y = Math.round(this._y+this._height/2+spacing/2);
			container._alpha += 5;
			if (container._alpha>90) {
				info.text = id;
				container._alpha = 100;
				delete this.onEnterFrame;
			}
		}
	};
};
function galleryChoice(q) {
	pArray = new Array();
	tArray = new Array();
	iArray = new Array();
	my_xml = new XML();
	for (var j = 0; j<curLength; j++) {
		this.th_nav["thmb"+j].removeMovieClip();
	}
	my_xml.ignoreWhite = true;
	my_xml.onLoad = function(loaded) {
		if (loaded) {
			gallery = this.firstChild.childNodes[q];
			curLength = gallery.childNodes.length;
			for (var i = 0; i<gallery.childNodes.length; i++) {
				pArray.push(gallery.childNodes[i].attributes.source);
				tArray.push(gallery.childNodes[i].attributes.thumb);
				iArray.push(gallery.childNodes[i].attributes.title);
			}
		}
		delay = setInterval(makeButtons, 50);
	};
	my_xml.load("gallery.xml");
}
function makeButtons() {
	tnNr = 0;
	clearInterval(delay);
	for (var i = 0; i<tArray.length; i++) {
		var thb = th_nav.thmb.duplicateMovieClip("thmb"+i, 1000+i);
		thb.id = i;
		thb._x = i%3*50;
		thb._y = Math.floor(i/3)*50;
	}
	loadButtons();
}
function loadButtons() {
	var tbox = th_nav["thmb"+tnNr].box;
	tbox.loadMovie(tArray[tnNr]);
	temp = this.createEmptyMovieClip("tmp"+tnNr, 999);
	temp.onEnterFrame = function() {
		bt = tbox.getBytesTotal();
		bl = tbox.getBytesLoaded();
		if (bt == bl && bt>4) {
			nextButton();
			delete this.onEnterFrame;
		}
	};
}
function nextButton() {
	if (tnNr<tArray.length-1) {
		tnNr++;
		loadButtons();
	} else {
		activateButtons();
	}
}
function activateButtons() {
	mainButtons();
	for (var i = 0; i<pArray.length; i++) {
		var but = th_nav["thmb"+i];
		but.id = i;
		but.onRelease = function() {
			container.loadPic(pArray[this.id], iArray[this.id]);
			disButtons2(this.id);
		};
	}
	container.loadPic(pArray[0], iArray[0]);
	disButtons2(0);
}
butArray = new Array();
butArray = ["gal1_btn", "gal2_btn", "gal3_btn", "gal4_btn"];
function mainButtons() {
	for (var i = 0; i<butArray.length; i++) {
		this[butArray[i]].id = i;
		this[butArray[i]].onRelease = function() {
			galleryChoice(this.id);
			disButtons(this.id);
		};
	}
}
function disButtons2(d) {
	for (var i = 0; i<tArray.length; i++) {
		if (i != d) {
			this.th_nav["thmb"+i].enabled = 1;
			this.th_nav["thmb"+i].box._alpha = 100;
		} else {
			this.th_nav["thmb"+i].enabled = 0;
			this.th_nav["thmb"+i].box._alpha = 50;
		}
	}
}
function disButtons(d) {
	for (var i = 0; i<butArray.length; i++) {
		if (i != d) {
			this[butArray[i]].enabled = 1;
			this[butArray[i]].gotoAndStop(1);
		} else {
			this[butArray[i]].enabled = 0;
			this[butArray[i]].gotoAndStop(2);
		}
	}
}
disButtons(0);
galleryChoice(0);

Open in new window

0
Comment
Question by:beginnersdevelopment
2 Comments
 
LVL 19

Accepted Solution

by:
moagrius earned 500 total points
ID: 34148959
you wouldn't be able to directly translate that from AS2 to AS3 - you'd need some restructuring.

for example, MovieClips no longer have getBytesLoaded() or getBytesTotal() - this only works for objects transacting with external assets, like Loader and URLLoader - and even then doesn't work exactly the same (there are no methods like that, but they dispatch events that have the information).

you can still use prototype methods, but best-practice would be to create a custom class and assign those methods as class members.

other than than, generally:

- properties are no longer prefixed with an underscore. "_alpha" is now "alpha", "_x" is now "x".  there are other naming changes as well, like "_xscale" is now "scaleX".
- use the "new" operator to create instances (new MovieClip()) instead of whatever.createEmptyMovieClip()
- event handlers are no longer assigned using instance.onEvent = function(){}.  now you add an event listener, and in general use named functions rather than anonymous ones.  you also can't delete them as is shown - they must be removed using the appropriate methods.
- you still get array access (this["whatever"]), but this might trip you up when used with instance names - it's preferred to use container.getChildByName("instanceName");
- XML is radically changed.  all data is loaded using the URLLoader object with instances of the URLRequest object - there is no longer an XML.load() method, nor does an XML object have an onLoad callback.
- "var" is now required - you can't say "spacing = 10;" - it must be "var spacing = 10;"
- datatyping is not required but is encouraged.  append ":DataType" to the end of variable names, e.g., "var spacing:Number = 10;";
- instead of tracking information in interval or enterframes, now you use events and event handlers.

hth
0
 

Author Closing Comment

by:beginnersdevelopment
ID: 34156371
Thanks for the follow up and how I would go about converting the file.
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access Control Entries lost in Windows folders 3 57
Linux Scripting 3 144
The Best Website Creation Tools 14 74
Redirecting an Outlook attachment to a specific folder? 3 58
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question