Hi,
I posted a msg on this before but my code has changed so much in mean time i thought it simpler to create a new thread.
An xml file contains multiple products each with their corresponding background image, foreground image, text and website. The LoadXML class loads this xml file and creates an array of each image, text and website. The Main class then loads each image from the array of background images in the method onBackgrLoad(). This is done through the use of a for loop which loops through the array of backgrounds (called hintergrund[]) and loads each one in turn. On tracing hintergrund[] I sucessfully receive a string of all the different background image paths. However when I examine the backgrRequest and backgrLoader they both contain null. The images therefore dont appear on stage but neither does an error message appear! The same thing happens for onImageLoad (this should load the foreground image) and onTextLoad.
Ive been stuck on this for SOOOOOOO LOOONG, its driving me crazy lol! :hurt:
(...)
public class Main extends Sprite
{
//____________________________________________________________________________Vars : Newly created
public var images : Vector.<DisplayObject>;
private var loaders : Vector.<Loader> = new Vector.<Loader>();
private var loader : URLLoader = new URLLoader();
private var backgr : Bitmap;
private var img : Bitmap;
private var titel : String;
private var cover : Sprite;
// private var textContainer : Container_Text = new Container_Text();
//____________________________________________________________________________Vars : From other classes
public var coverflow : CoverFlow;
private var bg : BG;
private var sb : ScrollPaneExample;
private var sl : ScrollLabels;
private var productSummaryLabel : ProductSummaryLabel;
public var loadXML:LoadXML;
// private var reflection : Reflection;
private var xmlData : XML;
private var hintergrund : Array;
private var pfad : Array;
private var maxProducts : int;
private var numOfProducts : int;
private var numOfCategories : int;
//____________________________________________________________________________Constructor
public function Main()
{
initBG();
trace("Step 0: New LoadXML being loaded in Main class");
loadXML = new LoadXML();
loadXML.addEventListener( Event.COMPLETE, onBackgrLoad);
trace("Test: XML Load Number of Products (Main class): " + numOfProducts);
}
//____________________________________________________________________________Methods
// Loads the backgr for each image.
private function onBackgrLoad(e : Event) : void // will this be a prob seein as class is sprite??
{
var backgrLoader : Loader = new Loader();
var xmlData : XML = loadXML.getXMLData();
var hintergrund : Array = loadXML.getBackgr();
var numOfProducts : int = loadXML.getNumOfProducts();
trace("Number of Products (Main class): " + numOfProducts);
trace("Hintergrund paths (Main class): " + hintergrund);
// On completetion of this method or in case of an error do the following:
backgrLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoad);
backgrLoader.addEventListener(IOErrorEvent.IO_ERROR, handleXMLError); // try takin this out: contentLoaderInfo.
trace("Step 5: Backgr images now being loaded.");
/* Create a template bitmap to hold the image info */
var templateBitmap : Bitmap;
var templateBitmapData : BitmapData;
// Loop through the background urls
// A summary should appear for each object once it is in the center
for (var i : int = 0; i < numOfProducts; i++)
{
var backgrRequest : URLRequest = new URLRequest(hintergrund*);
trace("Hintergrund*: " + hintergrund*);
trace("Trace backgrRequest: " + backgrRequest);
cover = new Sprite();
// Method 1
// titel = String(e.target.data);
// Method 2
// var titelString : String = titel*; // has to be a dynamic string so change this and put in container
// trace(titelString);
// Method 3
// var titel : TextField = event.target.String as TextField; // this is text so import as textfield? can i do this like this?
//titel shud be rotated. this can be done using bevel filter bt atm not supporting this (look at reflection probs)
try
{
backgrLoader.load(backgrRequest);
trace("Trace backgrLoader: " + backgrLoader.content);
} catch (error: ArgumentError) {
trace("An Argument Error has occurred.");
} catch (error: SecurityError) {
trace("A Security Error has occurred.");
} catch (error: Error) {
trace("An Error has occurred.");
}
trace("onBackgrLoad Loop: " + i);
templateBitmap = Bitmap(backgrLoader.content);
//templateBitmap = e.target.content;
//templateBitmapData = templateBitmap.bitmapData;
/* Attach the template BitmapData to each backgr image */
var backgrBitmap : Bitmap = new Bitmap(templateBitmapData);
cover.addChildAt(backgrBitmap, 0);
// coverHolder.addChild(cover);
// Method 1: target data into bitmap
// var backgrBitmap : Bitmap = e.target.data as Bitmap;
// Adds the backgr to the already exisiting backgrs inside the Bitmap "backgr"
// backgr += e.target.content as Bitmap;
//var myNewBackgr = e.target.loader; // Necessary?
// Method 2: create object
//BAD IDEA to create a bitmap obj since this cant be rotated or tweened
// var backgrObj : Object = backgrLoader.data as Object; or //e.target.data
// Method : Imagemultiloader
// var backgrBitmap : Object = (e.target as ImageMultiLoader).data
// // determine imagemultiloader!!
// Method 3: create template bitmap
///* Create a template bitmap to hold the image info */
// var templateBitmap:Bitmap = e.target.content;
// var templateBitmapData:BitmapData = templateBitmap.bitmapData;
// /* Loop through your tiles */
// for (var a:uint = 0; a < tilesWide; a++)
// {
// for (var b:uint = 0; b < tilesHigh; b++)
// {
// var tile:Sprite = new Sprite();
// /* Attach the template BitmapData to each tile */
// var tileBitmap:Bitmap = new Bitmap(templateBitmapData);
// tile.addChild(tileBitmap);
// tile.x = a * tile.width;
// tile.y = b * tile.height;
// tileHolder.addChild(tile);
// }
// }
// Method 4: Load straight into BitmapData
//var img1:BitmapData = BitmapData.loadBitmap("img2")
//var img2:BitmapData = new BitmapData(img1.width, img1.height, false)
// Method 5: Try with image holder
// Try with an image holder.
// backgrMc = imgHolder;
// var backgr : Bitmap = Bitmap(e.target.content);
//
// try {
// cover.removeChildAt(0); // should i take this out to ensure not just last image loads?
// } catch (error: Error) {
// trace("Catch error here.");
// }
// cover.addChildAt(backgr, 0);
}
}
public function onImageLoad(e : Event) : void
{
(...) }
public function onImageLoaded(event : Event) : void
{
// var xmlProductList : XML = xmlData.produkte.produkt;
// var xml : XML = new XML(event.target.data); // will this work now tht there r 3 things loaded?
// To create a shadow only UNDER the backgr image
backgr.filters = [new DropShadowFilter()]; //can this var backgr be used from above? i put them on public
// Turn xml data into three seperate Bitmap images and put this in a cover
// Insert all the images on top of each other in a single cover
// cover.addChildAt(backgr, 0); // At the back
// cover.addChildAt(img, 1); // On top
// cover.addChildAt(titel, 2); // On top // IS THIS POSSIBLE
//To create a shadow around the side of the whole image and the bottom
// cover.filters = [new DropShadowFilter()];
// Ensure cover is 20px smaller height + width
// coverDisplayX = -backgr.width / 2; // backgr is equal to whole image size so not necessary to speicify whole img
// coverDisplayY = -backgr.height / 2;
// coverDistanceX = -50;
// coverDistanceY = -50;
backgr.x = -backgr.width / 2;
backgr.y = -backgr.height / 2; // Height is too long but I managed to decrease pix to 75%
// cover.graphics.lineStyle(0, 0xFFFFFF); // Border around image
cover.graphics.drawRect(backgr.x, backgr.y, backgr.width, backgr.height);
images.push(cover); // images.push(imageLoader.content);
// Initiate the rest of the methods
// The nr of images on coverflow should not be more than number allowed on stage.
if(images.length <= maxProducts) // Used to be ==
{
initCoverflow();
}
else
{
trace("More images than the maxProducts stated by user. Please increase the maxProduct nr or delete some images.");
}
}
//____________________________________________________________________________Initiations
private function initCoverflow() : void
{
if(coverflow)
{
removeChild(coverflow);
coverflow = null;
}
coverflow = new CoverFlow(images);
coverflow.x = stage.stageWidth / 2;
coverflow.y = stage.stageHeight / 2;
addChildAt(coverflow, 1);
}
(...)
//____________________________________________________________________________Error catching
private function handleXMLError( event:IOErrorEvent ):void
{
trace("Fehler beim Aufrufen von XML.");
}
}
}
I also attached my XML file (produkte1) and my loadxml class.