Skip to main content
Known Participant
October 9, 2009
Answered

Trouble loading xml images...

  • October 9, 2009
  • 2 replies
  • 4684 views

I have loaded an XML file in the class LoadXML and have here created a method which parses the data and returns various arrays: an array of background urls (i called the array: hintergrund[]), an array of image paths (pfad[]), an array of website urls (website[]) and so forth. In the main class I would now like to load the backgrounds and images. I must have made a mistake in my onBackgrLoad() because I keep receiving the error msg:

Error #1084: Syntax error: expecting rightparen before colon.

I can´t see any paranthesis missing though...

Here are the relevant sections in my Main class:

package {

import flash.display.Sprite
;
import flash.net
.*;
import flash.display
.*;
import flash.events
.*;
import flash.display.Loader
;
import flash.filters.DropShadowFilter
;
import flash.net.URLRequest
;
import flash.text
.*;
// import de.container.text.Container_Text;

// To edit dropshadow. Atm not using.
import flash.filters.BitmapFilter
;
   
import flash.filters.BitmapFilterQuality
;

public class
Main extends
Sprite
{
 
//____________________________________________________________________________Vars : Newly created

 
public var images : Vector.<DisplayObject
>;
  private var
maxProducts : int
;
  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 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
;
//  private var reflection : Reflection; 

 
private var xmlLoad : LoadXML = new LoadXML
();
  private var
xmlData : XML = xmlLoad.getXMLData
();
  private var
hintergrund : Array = xmlLoad.getBackgr
();
  private var
pfad : Array = xmlLoad.getPath
();
  private var maxProducts : int = xmlLoad.getMaxProducts();
  private var
numOfProducts : int = xmlLoad.getNumOfProducts();
  private var
numOfCategories : int = xmlLoad.getNumOfCategories(); 


//____________________________________________________________________________Constructor

public function Main
()
{
 
initBG
();
 
onBackgrLoad(e : Event
);
}

//____________________________________________________________________________Methods
// Load the backgr for each image.
private function onBackgrLoad(e : Event) : void
// Take away : void ?
{
  
// A summary should appear for each object once it is in the center
  
for (var i : uint = 0; i < numOfProducts; i
++)
          {
    var
backgrLoader : Loader = new Loader
();
    var
backgrRequest : URLRequest = new URLRequest(hintergrund[i
]);

   
backgrLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoad
);
   
backgrLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, handleXMLError
);
    try
    {
    
backgrLoader.load(backgrRequest
);
    } catch (
error: ArgumentError
) {
    
trace("An Argument Error has occurred."
);
    } catch (
error: SecurityError
) {
    
trace("A Security Error has occurred."
);
    }

   
// OR can use method below without needing var backgrRequest
//    backgrLoader.load( new URLRequest( hintergrund ) );

   
var myNewBackgr = e.target.loader;
// Necessary?

    // Hold the backgrs inside the Bitmap
   
backgr = e.target.content as Bitmap
;

   
trace("onBackgrLoad Loop: " + i
);
          }
  }
 
// Load image that will lie above backgr. When event is completed call onTextLoad().
 
public function onImageLoad(e : Event) :
void
 
{  
  
// FOR statement: summary should appear for each object once it is in the center
  
for (var i: uint = 0; i < numOfProducts; i
++)
          {
    var
imageLoader : Loader = new Loader
();
    var
imageRequest : URLRequest = new URLRequest(pfad[i
]);

   
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
// change this to onTextLoad once method completed
   
imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, handleXMLError
);
   
imageLoader.load(imageRequest
);

    var
myNewImage = e.target.loader;
// necessary?

    // Hold the images inside the Bitmap
   
img = e.target.content as Bitmap
;

   
trace("onImageLoad Loop: " + i
);
          }
  } 


I also attached my LoadXML class and my XML file.

This topic has been closed for replies.
Correct answer CaioToOn!

Oh thanks! Here is the xml doc (sorry the comments are all in german!):

<?xml version="1.0"?>
<!-- The line above defines version of XML that is being used and the type of encoding -->

<produkte>

<!-- Bitte trage hierunter ein wie viel Produkte höchst Sie auf die Bühne haben möchte -->
<!-- <max>5</max> -->

<!--  WEB AUFTRITT PRODUKTE -->

<produkt>
  <kategorie>CNM.WebAuftritt</kategorie>
   <bild>
    <titel>CNM.Web.CMS</titel>
    <hintergrund>P:\Orgproj\Azubis_Prakt\CNM Redesign\Dokumente und Grafiken\Cards\Hintergrund\Card_Web.png</hintergrund>
    <pfad>P:\Orgproj\Azubis_Prakt\CNM Redesign\Dokumente und Grafiken\Cards\Bild\Bild1png.png</pfad>
   </bild>
  <website>http://www.yahoo.com</website> <!-- will be changed later once known -->
  <uebersicht><![CDATA[CNM.Web bietet Ihnen Rundum-Service: Gemeinsam mit Ihnen entwickeln und realisieren wir Lösungen, die präzise auf Ihre Anforderungen abgestimmt sind. Wir begleiten die Einführung technisch und organisatorisch. Auf der Basis professioneller Enterprise-Content-Management-Systeme (ECMS) und integrierter Datenbankanwendungen (.NET und JAVA) setzen wir diese Lösungen in zeitgemäßer Technologie für Sie um. ]]></uebersicht>
</produkt>

<produkt>
  <kategorie>CNM.WebAuftritt</kategorie>
   <bild>
    <titel>CNM.Web.AquaBrowser</titel>
    <hintergrund>P:\Orgproj\Azubis_Prakt\CNM Redesign\Dokumente und Grafiken\Cards\Hintergrund\Card_Web.png</hintergrund>
    <pfad>P:\Orgproj\Azubis_Prakt\CNM Redesign\Dokumente und Grafiken\Cards\Bild\Bild2png.png</pfad>
   </bild>
  <website>http://www.yahoo.com</website>
  <uebersicht><![CDATA[CNM.Web bietet Ihnen Rundum-Service: Gemeinsam mit Ihnen entwickeln und realisieren wir Lösungen, die präzise auf Ihre Anforderungen abgestimmt sind. Wir begleiten die Einführung technisch und organisatorisch. Auf der Basis professioneller Enterprise-Content-Management-Systeme (ECMS) und integrierter Datenbankanwendungen (.NET und JAVA) setzen wir diese Lösungen in zeitgemäßer Technologie für Sie um. ]]></uebersicht>
</produkt>

<!-- commented it all out till next part is finished -->

<!-- PROZESS OPTIMIERUNG PRODUKTE -->


<produkt>
  <kategorie>CNM.ProzessOptimierung</kategorie>
   <bild>
    <titel>CNM.PrO.CRM</titel>
    <hintergrund>P:\Orgproj\Azubis_Prakt\CNM Redesign\Dokumente und Grafiken\Cards\Hintergrund\Card_Pro.png</hintergrund>
    <pfad>P:\Orgproj\Azubis_Prakt\CNM Redesign\Dokumente und Grafiken\Cards\Bild\Bild3png.png</pfad>
   </bild>
  <website>http://www.hotmail.com</website>
  <uebersicht><![CDATA[Geschäftsprozesse wirtschaftlich zu steuern und kontinuierlich zu verbessern, ist zu einem wichtigen Thema geworden. Effizienz und Effektivität sind entscheidende Stellgrößen für Ihren Erfolg. CNM.PrO. Lösungen unterstützen Ihre internen Prozesse und Arbeitsabläufe. Schulung und Beratung runden das Angebot ab.]]></uebersicht>
</produkt>

<produkt>
  <kategorie>CNM.ProzessOptimierung</kategorie>
   <bild>
    <titel>CNM.PrO.DMS</titel>
   <hintergrund>P:\Orgproj\Azubis_Prakt\CNM Redesign\Dokumente und Grafiken\Cards\Hintergrund\Card_Pro.png</hintergrund>
   <pfad>P:\Orgproj\Azubis_Prakt\CNM Redesign\Dokumente und Grafiken\Cards\Bild\Bild4png.png</pfad>
   </bild>
  <website>http://www.hotmail.com</website>
  <uebersicht><![CDATA[Geschäftsprozesse wirtschaftlich zu steuern und kontinuierlich zu verbessern, ist zu einem wichtigen Thema geworden. Effizienz und Effektivität sind entscheidende Stellgrößen für Ihren Erfolg. CNM.PrO. Lösungen unterstützen Ihre internen Prozesse und Arbeitsabläufe. Schulung und Beratung runden das Angebot ab.]]></uebersicht>
</produkt>


</produkte>

I´ll also add my coverflow class so you  can see how the images are supposed to appear on stage:

package {

import flash.display.*;
import flash.events.MouseEvent;
import gs.TweenLite;
import gs.easing.*;
import flash.net.URLRequest;
import flash.net.navigateToURL;
   import fl.containers.ScrollPane; 
    import fl.events.ScrollEvent; 
    import fl.controls.ScrollBarDirection;
import fl.controls.ScrollBarDirection;
import flash.events.*;

public class CoverFlow extends Sprite {

  public var covers : Vector.<DisplayObject>;
  private var coverRotationY : Number = 60;
  // Original distance between covers was 200
  private var coverDistance : Number = 150;
  // Original zoom on images in background
  private var coverZ : Number = 250; //Not much difference compared to original 300
  // Original zoom on selected image in foreground (value 0 = original pix)
  private var selectedCoverZ : Number = .0;
  private var tweenDuration : Number = .6;
  private var easing : Function = Strong.easeOut;

  public function CoverFlow(covers : Vector.<DisplayObject>)
  {
   this.covers = covers;
   create();
   show(2);
   addEventListener(MouseEvent.CLICK, onClick);
   //addEventListener(MouseEvent.CLICK, onCenterImageClick);
  }
 
 
  //____________________________________________________________________________Create CoverFlow
 
  private function create(): void
  {
   for(var i : Number = 0; i < covers.length; i++)
   {
    var cover : DisplayObject = covers;   
    cover.rotationY = coverRotationY;
    cover.x = i * coverDistance;
//    cover.height = 100; //TRY
    addChildAt(cover, 0);
   }
  }
 
 
  //____________________________________________________________________________CoverFlow Tweening
 
  private function show(id : uint) : void // e : Event
  {
   for (var i : Number = 0;i < covers.length; i++)
   {
   
    var cover : DisplayObject = covers;
   
    // Tried putting if i == id as last statment to stop website coming up automatically but it still does since it then loops through again.
   
    if (i < id)
    {
     setChildIndex(cover, i);
     TweenLite.to(cover, tweenDuration, {x: (id - i + 1) * -coverDistance, z: coverZ, rotationY: -coverRotationY, ease:easing });
    } else if (i > id)
    {
     setChildIndex(cover, covers.length - 1 - i);
     TweenLite.to(cover, tweenDuration, {x: ((i - id + 1) * coverDistance), z: coverZ, rotationY: coverRotationY, ease:easing });
    } else if(i == id)
    {
     setChildIndex(cover, covers.length - 1);
     TweenLite.to(cover, tweenDuration, {x: 0, z: selectedCoverZ, rotationY: 0, ease:easing });
     // If center object then load website
     // PUT IF STATEMENT ?
//     onCenterImageClick(); //always complete this method and inside put whether or not it links further

// TRY WITH TARGETING e.currentTarget infront of listener
// change this to ensure that exact event is specified. uncomment once done.
//     e.currentTarget.addListener(MouseEvent.CLICK, onCenterImageClick); // here directly state tht only on click
//     navigateToURL(new URLRequest("http://www.google.com"), "_blank"); // Webseite für CMN.Security // keep this on for readme
   
   
   
// or use something similar to this:
//
// for( ... ) {
//   ...
//   cover.addEventListener(MouseEvent.CLICK, sliderClick);
//   cover.myurl = XMLdata["url" +i];
//}
//
//function sliderClick(e:MouseEvent) {
//   var openUrl:URLRequest = new URLRequest(e.currentTarget.myurl);
//   navigateToURL(openUrl);
//}

   
    }
   }
  }
 
  //____________________________________________________________________________Mouse functions on CoverFlow
 
  private function onClick(event : MouseEvent) : void
  {
   // Always display product clicked on as center image
   var cover : DisplayObject = event.target as DisplayObject;
   var index : int = covers.indexOf(cover);
   show(index); // Show the index number of the current displayed object  
  }
 
//  //  this is already covered by productSummaryLabel - where is the best to keep it?
//  private function onCenterImageClick(event : MouseEvent) : void
//  {
//   //if click then load...
//   // Code already in productsummarylabel class
//  }
}
}


Oh! Now I see it.

The problem is the way you're reading your XML.

The correct path to the hintergrund node is xmlData.produkt.bild.hintergrund, not xmlData.produkte.produkt.bild.hintergrund.attributes(). All other variables are also with the same problem.

Take a look at the documentation about handling XML and here is a complete guide to handle XML in E4X format: http://www.ecma-international.org/publications/standards/Ecma-357.htm

Regards,

CaioToOn!

2 replies

Inspiring
October 9, 2009

in constructor:

onBackgrLoad(e : Event);
is wrong call of method. You must call it like this:

onBackgrLoad( new Event(Event.COMPLETE) );

but generating event like this is not a good practise. I suggest you to redisign the code.( in case you are not copy pasted it)

stephshAuthor
Known Participant
October 9, 2009

Thanks that already helped, now my application actually compiles! Nothing appears though so I assume there is still a mistake somewhere... Yes I wrote the code myself hence why it doesnt work!! How could I rewrite it to make it better?

Inspiring
October 9, 2009

I think that is not all code. In constructor you call a method named: initBG, but in code those method not exist. Also in onImageLoad you have some kind of recursion. This method will be executed for furst time when background is loaded ( is initBG is onImageLoad? ). in this first execution you will start loading all from numOfProducts, but on every loader you attach  onImageLoad  on COMPLETE event. So when some image is loaded it will start loading again all images from numOfProducts.

Also there is a missing mathod - handleXMLError. Are you use a strict mode in you compiler?

Also if main is document class it must extend MovieClip class not sprite

stephshAuthor
Known Participant
October 9, 2009

Stupid me, I posted the wrong error msg!! The error message I keep getting is that BackgrLoad() contains an incorrect number of arguments. One argument is recommended.