How do i load an image through XML?

Hi.
My code is below. What I am trying is to dinamically load images from xml. I attach the holder from the library, and when i try to target it and addChild to him i get an error:
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("links.xml"));
var xmlLength:int;
var iconPos:Number = 0;
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
var xmlLength = xmlData.link.length();
for (var i=0; i<xmlLength; i++) {
var d:MovieClip = new icon();
content_mc.addChild(d);
d.name = "d"+i;
var target:DisplayObject = content_mc.getChildByName("d"+i);
var ldr:Loader = new Loader();
ldr.load(new URLRequest(xmlData.link[i].icon));
target.addChild(ldr);
How can i make this happen and load the image into it's holder?
Thank you.

Code from adobe's sample packages cut&&paste&&edit:
AS4 code:
import flash.events.IOErrorEvent;
var fotoElenco:Array;
var fotoXML:XML;
var fotoURLRequest:URLRequest=new URLRequest();
var fotoURLLoader:URLLoader=new URLLoader();
var fotoLoader:Loader=new Loader();
var fotoPosition:Number=0;
var errorMessage:TextField=new TextField();
caricaFoto();
function caricaFoto():void
    addChild(errorMessage);
    fotoURLRequest.url="gallery.xml";
    fotoURLLoader.load(fotoURLRequest);
    fotoURLLoader.addEventListener(Event.COMPLETE, showFoto);
    fotoURLLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorEventXML);
function ioErrorEventXML(event:IOErrorEvent):void
    manageErrorMessage(true, 0);
function manageErrorMessage(val:Boolean, num:Number):void
    if(val && num==0){
        errorMessage.x=stage.stageWidth/2;
        errorMessage.y=stage.stageHeight/2;
        errorMessage.text="Errore caricamento file XML";
    if(val && num==1){
        errorMessage.x=stage.stageWidth/2;
        errorMessage.y=stage.stageHeight/2;
        errorMessage.text="Errore caricamento file IMMAGINE";
function showFoto(event:Event):void
    fwd_mc.buttonMode=true;
    back_mc.buttonMode=true;
    back_mc.addEventListener(MouseEvent.CLICK, manageFoto);
    fwd_mc.addEventListener(MouseEvent.CLICK, manageFoto);
    fotoElenco=new Array();
    fotoXML=XML(fotoURLLoader.data);
    for each(var prop:XML in fotoXML.foto)
        fotoElenco.push({url:prop.@url, didascalia:prop.@didascalia});
    viewFoto(fotoPosition);
    gallery_mc.addChild(fotoLoader);
    manageButton();
function manageButton():void
    if(fotoPosition<1){
        back_mc.visible=false;
    }else{
        back_mc.visible=true;
    if(fotoPosition>=fotoElenco.length-1){
        fwd_mc.visible=false;
    }else{
        fwd_mc.visible=true;
function manageFoto(event:MouseEvent):void
    switch(event.currentTarget)
        case fwd_mc:
            if(fotoPosition<fotoElenco.length-1)
                fotoPosition++;
        break;
        case back_mc:
            if(fotoPosition>0)
                fotoPosition--;
        break;
    viewFoto(fotoPosition);
function viewFoto(num:Number):void
    fotoLoader.load(new URLRequest(fotoElenco[num].url));
    fotoLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorEventIMG);
    didascalia_txt.text=fotoElenco[num].didascalia;
    manageButton();
function ioErrorEventIMG(event:IOErrorEvent):void
    manageErrorMessage(true, 1);
XML code:
<?xml version="1.0" encoding="UTF-8"?>
<gallery>
    <foto url="img/immagine1.jpg" didascalia="Didascalia 1 foto"/>
    <foto url="img/immagine2.jpg" didascalia="Didascalia 2 foto"/>
    <foto url="img/immagine1.jpg" didascalia="Didascalia 1 foto"/>
    <foto url="img/immagine2.jpg" didascalia="Didascalia 2 foto"/>
</gallery>

Similar Messages

  • How do I load an image in WEB-INF?

    How do I load an image from WEB-INF with JSP's? I'm using Glassfish and
    NB.
    Filter code:
    String path = filterConfig.getServletContext().getContextPath();
    contextPath = "http://localhost:8080" + context + path;
    String duke = contextPath + "/duke.gif";
    which results in the following html:
    <img src="http://localhost:8080/WebApplication/duke.gif">
    Which is fine, but any user gets to access that image. I want to move
    the image to WEB-INF so that it's not accessible for users.
    see also:
      NetBeans Forums - how to load an image from WEB-INF?

    No i dont think so..... I need to download the jar file through the JNLP which contains those image files.
    Only then the JNLPClassLoader returns the Image file otherwise it returns null.
    (actually i assumed, it loads all those files into it and keeps it as the Resources. I don know whether it is right or not..)
    eg., I download my img.jar in C:\Downloads using JNLPClassLoader which contains New.gif.
    getClass().getResource("New.gif") exactly returns the URL C:\Downloads\img.jar!\New.gif.
    But my ClassLoader returns null for this getClass().getResource("New.gif").
    I also tried calling getClass().getResource("C:\Downloads\img.jar!\New.gif") It simply returns null.
    Im sure that I have the Image file in that path.

  • Send Image through xml file

    Hey guys,
    I want to send an JPEG image through xml file. i dont want to just give the URL of the image but i want to actually send the image through xml. Im new in XML so can you please give me a working sample code.
    Thank you so much.

    Working code will not be difficult to write. Jpeg or other binary info can be encoded in xml using base64 encoding or some other encoding algorithm.
    After base64 encoding you will get some text which will be the base64 equivalent of the image data. This text can be placed in CDATA section of your image element and transferred.
    On the receiving end you will need to decode the text. After this what u have is the binary data for ur image.
    It will not be difficult to find libraries for base64 encodin/decoding on the net.
    Hope it helps

  • Pre-loading external images for XML-based gallery

    I'm working-on an XML-based photo gallery here:
    http://www.unionandparkwood.com/demo/flash_gallery/
    It works how I want it, except that the first time a
    thumbnail is clicked for an image, it pauses long enough to skip
    the fade. If you click-through the images a second time, you'll see
    that it works smoothly. My guess is that the first time the
    thumbnail is clicked, the image isn't cached, yet.
    I tried to fix this by creating a JavaScript file for the
    page to pre-load each image and thumbnail:
    0003a = new Image;
    0003a.src = "images/Down-Range.jpg";
    0003b = new Image;
    0003b.src = "thumbnails/Down-Range.jpg";
    But that didn't work. What would be the best way to do this?
    I included a link to "Download ZIP" of the FLA project on
    this page, too, because it wouldn't be easy for me to describe
    what's happening. In a nutshell, a thumbnail click launches a
    function that loads the appropriate image into the main image
    holder. What seems to be happening the first time is the image
    isn't loaded before the fade is finished, so the image just appears
    after a short pause the first time.

    >>What seems to be happening the first time is the
    image isn't loaded before
    >>the fade is finished, so the image just appears after
    a short pause the
    >>first time.
    As has been said many times in thos forum - use the
    MovieClipLoader class to
    load images, and then use that class' onLoadInit method to do
    things with
    the loaded image. Loading is asynchronous - you _have_ to
    wait until the
    image is done loading before doing a fade.
    Dave -
    www.offroadfire.com
    Head Developer
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.adobe.com/communities/experts/

  • How to dynamically load an Image into a TableView when its row/cell becomes visible?

    Hi,
    I am building an application that shows tables with large amounts of data containing columns that should display a thumbnail. However, this thumbnail is supposed to be loaded in the background lazily, when a row becomes visible because it is computationally too expensive to to this when the model data is loaded and typically not necessary to retrieve the thumbnail for all data that is in the table.
    I have done the exact same thing in the past in a Swing application by doing this:
    Whenever the model has changed or the vertical scrollbar has moved:
    - Render a placeholder image in the custom cell renderer for this JTable if no image is available in the model object representing the corresponding row
    - Compute the visible rows by using getVisibleRect and rowAtPoint methods in JTable
    - Start a background thread that retrieves the image for the given rows and sets the resulting BufferedImage in a custom Model Object that was used in the TableModel (if not already there because of an earlier run)
    - Fire a corresponding model change event in the EDT whenever an image has been retrieved in the background thread so the row is rendered again
    Btw. the field in the model class holding the BufferedImage was a weak reference in this case so the memory can be reclaimed as needed by the application.
    What is the best way to achieve this behaviour using a JFX TableView? I have so far failed to find anything in the API to retrieve the visible items/rows. Is there a completely different approach available/required that uses the Cell API? I fail to see it so far.
    Thanks in advance for any hints here.

    Here’s what I have tried so far:
    I have defined a property in my model object that contains a weak reference to the image that is expensive to load. I have modeled that reference as an inner class to the object so I have a reference to its enclosing object. That is necessary because my cell factory otherwise has no access to the enclosing model object, which it needs to trigger loading the image in the background.
    The remaining problems I have is, that I don’t have sufficient control over the loading process, i.e. I need to delay the loading process until scrolling has stopped and abort it as soon as the user starts scrolling again and the visible content changes. Imagine that loading an image for a table row (e.g. a thumbnail for a video) takes 200ms to load and a user quickly scrolls through a few hundred records and then stops. With my current set-up, the user has to wait for all loading processes that were triggered in the cell factories to finish until the thumbnails of the records they are looking at will appear (imagine an application like finder to be implemented like that, it would simply suck UX-wise). In my swing application a background thread that loads images for the visible records is triggered with a delay and stopped as soon as the visible content changes. This works well enough for a good user experience. I don’t see how I can do this based on the cell API. It is nice to have all this abstracted away but in this case I do not see how I can achieve the same user experience as in my swing application.
    I also tried registering a change listener to the TreeCell’s visible property to make that control the image loading but I don’t seem to get any change events at all when I do that.
    I must be missing something.

  • Loading Single Image Via XML

    Hey guys, I am trying to load a single image on to the stage via an xml file.
    Here is my xml file
    <?xml version="1.0" encoding="utf-8"?>
        <pictures>
            <pic>image1.jpg</pic>
        </pictures>
    I'm trying to figure out the actionscript 3 code but I don't know how to code it.
    If someone can please point me to the code or tutorial, it would be much appreciated.

    You would load the xml by doing this:
    var req:URLRequest = new URLRequest("xmlfilename.xml");
    var ldr:URLLoader = new URLLoader();
    ldr.addEventListener(Event.COMPLETE,xmlLoaded);
    ldr.load(req);
    function xmlLoaded(e:Event){
      var xml:XML = XML(e.target.data);
    //see * below..
    * then the code to load the image could go in the xmlLoaded function (in place of that //see below line), and would look like this:
    var imgreq:URLRequest = new URLRequest(xml.pictures.pic[0]);
    var imgldr:Loader = new Loader();
    imgldr.load(imgreq);
    addChild(imgldr);
    Normally you might add a listener to the Loader's contentLoaderInfo, so that you could then size or position the image before adding it to the stage. But hopefully the above code would get you as far as having the image in the top left of the stage.
    Read up more on Loader, URLRequest, URLLoader, and XML, to get a sense of the various parts of the whole process.

  • Set "Referer" when loading an Image through Toolkit

    To load an Image using an HttpURLConnection, I use the abstract java.awt.Toolkit.getImage(URL url) method, which is implemented by sun.awt.windows.WToolkit. This method uses the HttpURLConnection to load the Image.
    The problem I have, is that I don't know how I can set the HTTP "Referer" request header. There is a method in the HttpURLConnection called setRequestProperty(String key, String value), which I could use, but I can't reach the HttpURLConnection being used to load the Image.
    I would consider another way to load Images, but that would mean quite a bit of refactoring. I would prefer not to use Reflection, though.

    I did look at the HttpsURLConnection (of which we also have our own implementation), but that still doesn't solve the problem, unfortunately.
    Is there maybe another way to load an image from an HttpURLConnection or HttpsURLConnection? If there's a way that I can provide or access the connection being used and still get an Image object, I would be a happy man!

  • How can I send an image through a WebService

    Hi,
    I'm trying to send an image through a WebService to a mobile phone, but I can't get it working.
    Anyone knows how I can send an image on the server side, and receive it on the client side?
    Thanks for your help.

    Hope this will help
    String encodingStyleURI = org.apache.soap.Constants.NS_URI_SOAP_ENC;
    SOAPMappingRegistry smr = new SOAPMappingRegistry();
    BeanSerializer beanSer = new BeanSerializer();
    try {
    // Build the call.
    Call call = new Call();
    call.setSOAPMappingRegistry(smr);
    call.setTargetObjectURI("urn:filereceiver");
    call.setMethodName("loopFile");
    call.setEncodingStyleURI(encodingStyleURI);
    Vector params = new Vector();
    DataSource ds = new ByteArrayDataSource(new File(fname),
                                  null);
    DataHandler dh = new DataHandler(ds);
    params.addElement(new Parameter("addedfile",
                             javax.activation.DataHandler.class, dh, null));
    params.addElement( new Parameter( "filename", String.class,fname, null ) );
    call.setParams(params);
    // Invoke the call.
    Response resp;
    try {
         System.out.println(url);
    resp = call.invoke(url, "");
    } catch (SOAPException e) {
              FLAG          ="NO";
              System.err.println("Caught SOAPException (" +
                        e.getFaultCode() + "): " +
                        e.getMessage());
              e.printStackTrace();
    return FLAG;
    // Check the response.
    if (!resp.generatedFault()) {
    Parameter ret = resp.getReturnValue();
    if (ret == null){
    System.out.println("No response.");
              FLAG="NO";
    else {
              // System.out.println("Response: " + resp);
    // printObject(ret.getValue());
    } else {
    Fault fault = resp.getFault();
              FLAG          ="NO";
    System.err.println("Generated fault: ");
    System.err.println(" Fault Code = " + fault.getFaultCode());
    System.err.println(" Fault String = " + fault.getFaultString());

  • How  can I  load an  image  in a scene?

    I want to load an image in a scene and I have tried it using the
    steve morris example( HAVI example ) , I am using a STB and when I send my xlet I don�t see this imagen at the tv.
    Source code is available from
    http://www.interactivetvweb.org/resources/code/havi/HaviXlet.zip
    Somebody knows another way to do it ???

    I assume you mean a JLabel as an AWT Label cannot display an Image.
    // POINT THE IMAGE BACK TO THE SERVER FROM WHICH THE APPLET WAS DOWNLOADED
    // BY USING GETCODEBASE(). OMIT THAT AND YOU WILL SEE THAT YOU GET A SECURITY
    // EXCEPTION AS THE APPLET WILL TRY TO LOCTE THE IMAGE ON THE LOCAL MACHINE AND
    // APPLETS BY DEFAULT CANNOT ACCESS RESOURCES ON THE CLIENT
    // assumes .gif file exists in same directory as HTML running the Applet
    Image image = getImage(getCodeBase(), "ImageName.gif");
    ImageIcon icon = new ImageIcon(image);
    JLabel - new JLabel(icon);
    // check out the getScaledInstance() method of Image class to resize your image

  • How can i load a image into a midlet?

    Hi, i placed the png file together wif the midlet in the src directory.
    Image img = Image.createImage("title.png");
    I tried the above code but when i try to load the image in got this error
    Failed loading image.
    anione can help?

    just place your file in /res/ directory not in /src/

  • How to add styles to image in XML view ?

    Is it possible to add styles to Images in XML view ?
    <Image alt="alternate text " src = " " />
    I tried adding sytle= "align : right " but its not working. I just want to align this element in the view to the right.

    Hi Micheal,
    Pleas see the below code.
    View:
    <core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
      controllerName="testing.imageXml" xmlns:html="http://www.w3.org/1999/xhtml">
      <Page title="Image">
      <content>
      <Image id="img1" alt="alttextimage" src="images/img1.jpg" />
      </content>
      </Page>
    </core:View>
    Controller:
    onBeforeRendering: function() {
      this.getView().byId("img1").addStyleClass("myimage");
    Index.html :
    <!DOCTYPE HTML>
    <html>
      <head>
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>
      <script src="resources/sap-ui-core.js"
      id="sap-ui-bootstrap"
      data-sap-ui-libs="sap.m,sap.ui.commons"
      data-sap-ui-theme="sap_bluecrystal">
      </script>
      <script>
      sap.ui.localResources("testing");
      var app = new sap.m.App({initialPage:"idhome1"});
      var page = sap.ui.view({id:"idhome1", viewName:"testing.imageXml", type:sap.ui.core.mvc.ViewType.XML});
      app.addPage(page);
      app.placeAt("content");
      </script>
      <style>
      .myimage{float:right !important; width:300px; height:200px;}
      </style>
      </head>
      <body class="sapUiBody" role="application">
      <div id="content"></div>
      </body>
    </html>
    Output :
    Regards,
    KK

  • Problem loading Image through XML!

    Hi,
      I am Akshay and am beginner in this forum. I am trying to load images using flickr API and having problem.
    I am doing it in following fashion:
    1) I am calling the Httpservice to get the xml through flickr API as
    <s:HTTPService id="photoService" url="http://api.flickr.com/services/feeds/....FullAPI" resultFormat="e4x" result="photoResultHandler(event);" fault="photoFaultHandler(event);"/>
    2) In photoResultHandler I am retrieving the XML
    private function photoResultHandler(re:ResultEvent):void
    photoXml= re.result as XML;
    However, I am struggeling to retireve elements from photoXML and then use it to display image in :
    <mx:Image  id="img0" x="151" y="98" width="520" height="291"/>
    The XML structure is as below:
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <feed">
    <entry>
         <author>  </author>
         <link rel="enclosure" type="image/jpeg" href="http://farm5.static.flickr.com/4484460580_04bbced2d8_o.jpg"/>
    </entry>
    <entry>
    </entry>
    I need to load the href value of link  which can be found in feed-->entry-->link in the above xml.
    Please help!
    -Akshay

    Hello Dave,
       Thanks for your prompt reply. Here's the mxml code :
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
       xmlns:s="library://ns.adobe.com/flex/spark"
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" creationComplete="photoService.send()"  minHeight="600">
    <fx:Script>
    <![CDATA[
    import mx.controls.Alert;
    import mx.events.FlexEvent;
    import mx.events.MoveEvent;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    [Bindable]
    public var photoXml:XML;
    private function photoResultHandler(re:ResultEvent):void
    photoXml= re.result as XML;
    //var src :int =  "{photoXml.feed.entry.updated}" as int;
    img0.source= String(photoXml.entry[0].link[1].@href);
    private function photoFaultHandler(fe:FaultEvent):void
    Alert.show(fe.fault.message);
    ]]>
      </fx:Script>
    <fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    <s:HTTPService id="photoService" url="http://api.flickr.com/services/feeds/photos_public.gne?id=48951865@N07" resultFormat="e4x" result="photoResultHandler(event);" fault="photoFaultHandler(event);"/>
    </fx:Declarations>
    <mx:Image  id="img0" x="151" y="98" width="520" height="291"/>
    </s:Application>
    Hope it helps you in finding out the problem...DO let me know your thouhgts
    Thanks again for your replies so far......
    -Akshay

  • How do I load an image w/o loading the whole page?

    On my site I have tons of images (I'm an artist) and in the gallery where my images are viewed, "pastels", I have layed out 9 blocks/squares of images and when one of the blocks is clicked upon, I'd like the image to change in the view, but not reload the whole page. Am wondering how in iWeb it can be done to have just the newly selected image change out instead of the whole page load up. Does this make any sense?
    Help and your comments are encouraged here on how to make it more user friendly.
    http://web.mac.com/makinart

    So, let me understand what you're saying here....
    Textwrangler is a program I can download (free, I see) and it can process a multitude of pages. Once I get the JavaScript (the HTML code that enables the image to change out), (still have to find that one on the net), then I can take the JavaScript, enter it by using Textwrangler into my html coding. How will I know where the JavaScript is to be placed in the html with all that coding, how is a newbie to figure this out? Is the html code for my iweb site located in my "published folder"? Afterwards, I would best save the whole iweb site as a folder, then upload it to .mac as a file? Any changes I make on Iweb and republish will be lost? Yikes! There's something to tell the iweb programmers!
    I can tell you this, that it may be well over my head!

  • How do you load an image from an external homepage?

    Hi,
    I am searching for a method to load images from an external homepage. I do not want to use an application to do this. How can I achieve this. I know how to load texts from external pages but i can not immagine to download an immage via readLine. It would be nice if you could paste some code.
    I hope you can help me.

    Look at the URL object in the API, you use that and the associated InputStream.

  • Load Commodity codes through XML

    Hi,
    I'm trying to upload the commodity codes through an XML file.
    Transaction code - /SAPSLL/LLNS_UPL102
    I'm getting the following error.  Can someone help me with this.  Can anyone send me a file with the correct format which was accepted here earlier.
    Error during consistency check for numbering scheme : Initial load
    Message no. /SAPSLL/CORE_LLNS060
    Diagnosis
    The file to be uploaded is an initial file. This means that numbers and the corresponding scheme definition must not already exist in the system.
    System Response
    Processing is suspended.
    regards
    Surender

    Hi,
    I'm trying to upload the commodity codes through an XML file.
    Transaction code - /SAPSLL/LLNS_UPL102
    I'm getting the following error.  Can someone help me with this.  Can anyone send me a file with the correct format which was accepted here earlier.
    Error during consistency check for numbering scheme : Initial load
    Message no. /SAPSLL/CORE_LLNS060
    Diagnosis
    The file to be uploaded is an initial file. This means that numbers and the corresponding scheme definition must not already exist in the system.
    System Response
    Processing is suspended.
    regards
    Surender

Maybe you are looking for

  • Vga monitor fault

    Hello everyone! I have a problem with when switch users from one to another on windows xp I get a vga monitor driver fault. I've updated my vga drivers and direct x but I still have the same problem.

  • I see few purple vertical lines on my air mac coming on and off?

    Hello dears? I recently see few lines of purple colour showing on my screen of my my Mac Air OS X 10-8-5 . Processor 1.6 GHz intel Core i5. Memory  4 GB 1333 MHz DDR 3.   Anyone with advice what to do is really appreciated.

  • Passing Presentation variblae to the logical column in the rpd

    Hi, Can some one please tell me how to pass presentation variable to RPD logical column i am capturing a date from prompt and defining a status column based on the date user selects in the prompt, can some please tell me how to achieve this.. Thanks

  • Win8 CS5 serial number is not valid for this product

    trying to install my CS5 on a 2nd machine - a win 8 64bit machine. i purchased on my macbbok pro. my cs5 is saying the serial number is not valid for this product

  • Sometimes cannot save project because file is locked

    Using MAC OS X 10.3.9 and CS 2 Sometimes it happens in Illustrator that the file cannot be saved, it says that the file is locked for use. I remember the same problem also from PhotoShop 6 or something on Windows WX computers, so it is not a MAC or I