Pulling data from Class Array onto a MovieClip
I am trying to create this slide show application that will show product information (Tennis Rackets) based on diffrent categories. A great programmer advised me that OOP would be a way to go, however i am having a difficulty with it.
I created:
A document class called CustomClass --> this class downloads all XML data from the server and pushing the content of it into Arrays based on a category.These arrays are public, there is also a funciton iterateArray which places the children information somewhere.
I would like to have 3 diffrent movie clips
1st Screen -> Welcome Message
2nd Screen -> First Array Displayed
3rd Screen -> Second Array Dispalyed
package {
import flash.display.*;
import fl.transitions.*;
import fl.transitions.easing.*;
import flash.net.*;
import flash.events.*;
import flash.text.*;
import flash.text.AntiAliasType;
import flash.utils.*;
import bucket_right;
import bucket_left;
import firstScreen;
import secondScreen;
public class CustomClass extends MovieClip {
[Embed(source="C:/WINDOWS/Fonts/Eurosti.ttf", fontFamily="Euro")]
public var EuroEmbedded:Class;
//XML responsible variables
private var xmlLoader:URLLoader;
private var xmlContainer:XML;
private var xmlList:XMLList;
//Array specific variables
public var rackUSA:Array;
public var rackOther:Array;
public var imagesArray:Array;
//Position Variables
public var position:Number;
//Movie Clip Related Data
public var bucket:MovieClip;
public var firstScreenShow:MovieClip;
public var secondScreenShow:MovieClip;
//Text Field Formatting
private var brandnameTxt:TextFormat;
private var detailsTxt:TextFormat;
private var priceTxt:TextFormat;
public var euroEmbeddedFont:Font;
private var fontNeeded:String;
//Set up Timer Vars
private var applicationStart:Timer;
private var delay:Number;
private var repeat:Number;
//Positioning Variable
private var positionBuckets:Boolean = true;
//This is the constructor of the application
public function CustomClass() {
euroEmbeddedFont = new EuroEmbedded();
fontNeeded = euroEmbeddedFont.fontName;
position = 5;
rackUSA = new Array();
rackOther = new Array();
imagesArray = new Array();
delay = 2000;
repeat = 1;
applicationStart = new Timer(delay, repeat);
LoadXML();
}
private function LoadXML() {
xmlLoader = new URLLoader();
xmlLoader.load(new URLRequest("http://localhost/xml/index.php"));
xmlLoader.addEventListener(Event.COMPLETE, populateInfo);
}
public function populateImages(imgname:String, imgurl:String):* {
var imageLoader:Loader = new Loader();
//imgname = imgname.split(".gif").join("");
//imageLoader.name = imgname;
//imagesArray.push(imageLoader);
imageLoader.load(new URLRequest(imgurl));
return imageLoader;
}
public function getArray(arrayName:Array) {
return arrayName;
}
/*public function startApplication() {
applicationStart.start();
applicationStart.addEventListener(TimerEvent.TIMER_COMPLETE, firstScreen);
}
public function firstScreen(e:TimerEvent) {
removeChild(secondScreenShow);
applicationStart.reset();
applicationStart.removeEventListener(TimerEvent.TIMER_COMPLETE, firstScreen);
firstScreenShow = new firstScreen();
addChild(firstScreenShow);
//firstScreenShow.iterateArray(rackUSA);
applicationStart.start();
applicationStart.addEventListener(TimerEvent.TIMER_COMPLETE, secondScreen);
}
public function secondScreen(e:TimerEvent) {
applicationStart.reset();
applicationStart.removeEventListener(TimerEvent.TIMER_COMPLETE, secondScreen);
removeChild(firstScreenShow);
secondScreenShow = new secondScreen();
addChild(secondScreenShow);
//secondScreenShow.iterateArray(rackOther);
applicationStart.start();
applicationStart.addEventListener(TimerEvent.TIMER_COMPLETE, firstScreen);
}*/
public function setFontFormat() {
//Text Formatting for Brand Name Field
brandnameTxt = new TextFormat();
brandnameTxt.font = fontNeeded;
brandnameTxt.color = 0x006699;
brandnameTxt.size = 20;
brandnameTxt.bold = true;
//
//Text Formatting for Country/Material
detailsTxt = new TextFormat();
detailsTxt.font = fontNeeded;
detailsTxt.color = 0x006699;
detailsTxt.size = 10;
detailsTxt.bold = false;
//Text Formatting for Country/Material
priceTxt = new TextFormat();
priceTxt.font = fontNeeded;
priceTxt.color = 0x9DE36E;
priceTxt.size = 20;
priceTxt.bold = true;
}
public function tweenBucket(bucket:MovieClip) {
var bucketImgTrans = new TransitionManager(bucket);
bucketImgTrans.startTransition({type:Zoom, direction:Transition.IN, duration:3, easing:Strong.easeOut});
}
private function iterateArray(contentInfo:Array) {
this.setFontFormat();
for (var c:uint = 0; c < contentInfo.length; c++) {
var brand:TextField = new TextField();
var country:TextField = new TextField();
var made:TextField = new TextField();
var cost:TextField = new TextField();
var img:Loader;
brand.embedFonts = true;
img = contentInfo.picture;
brand.text = contentInfo.brand;
country.text = contentInfo.country;
made.text = contentInfo.made;
cost.text = contentInfo.cost;
if (positionBuckets) {
bucket = new bucket_left();
//Align Data
bucket.y = position;
bucket.x = 70;
brand.x = -50;
brand.y = -35;
country.x = -45;
country.y = -10;
made.x = -45;
made.y = 5;
cost.x = 45;
cost.y = -10;
img.x = -105;
img.y = -35;
brandnameTxt.align = TextFormatAlign.LEFT;
priceTxt.align = TextFormatAlign.LEFT;
positionBuckets = false;
} else {
bucket = new bucket_right();
//Align Data
bucket.y = position;
bucket.x = 240;
brand.x = -50;
brand.y = -35;
country.x = -45;
country.y = -10;
made.x = -45;
made.y = 5;
cost.x = -110;
cost.y = -10;
img.x = 70;
img.y = -35;
brandnameTxt.align = TextFormatAlign.RIGHT;
positionBuckets = true;
}
brand.setTextFormat(brandnameTxt);
country.setTextFormat(detailsTxt);
made.setTextFormat(detailsTxt);
cost.setTextFormat(priceTxt);
//this.tweenBucket(bucket);
addChildAt(bucket, 0);
bucket.addChild(DisplayObject(img));
bucket.addChild(brand);
bucket.addChild(country);
bucket.addChild(made);
bucket.addChild(cost);
position += 70;
}
}
private function populateInfo(event:Event) {
//Incoming XML Data
xmlContainer = new XML(event.target.data);
xmlList = xmlContainer.product;
//
//Variables to hold the string
var brandTxt:String;
var country:String;
var material:String;
var price:String;
var image:String;
for (var i:uint = 0; i < xmlList.length(); i++) {
if (xmlList.country.text() == "USA") {
brandTxt = xmlList.brand.text();
country = "product of " + xmlList.country.text();
material = "made of " + xmlList.material.text();
price = "$" + xmlList.price.text();
image = xmlList.image.text();
rackUSA.name = brandTxt.toLowerCase();
var imgVar:* = this.populateImages(image, "http://localhost/rackets/" + image);
rackUSA.push({brand: brandTxt, country: country, made: material, cost: price, pic: image, picture: imgVar});
//addChild(DisplayObject(rackUSA[0].picture));
} else if (xmlList.country.text() == "Other") {
brandTxt = xmlList.brand.text();
country = "product of " + xmlList.country.text();
material = "made of " + xmlList.material.text();
price = "$" + xmlList.price.text();
image = xmlList.image.text();
var imgVarOther:* = this.populateImages(image, "http://localhost/rackets/" + image);
rackOther.push({brand: brandTxt, country: country, made: material, cost: price, pic: image, picture: imgVarOther});
}
}
//this.startApplication();
}
}
}
If i have movie clip named firstScreen how do i populate with data from the array rackUSA, using the iterateArray funtions
I tried in a movieClip
CustomClass.iterateArray(rackUSA); //but this does not work
Any suggestions