A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: Load .JPG in .SWF via .XML

  1. #1
    Member
    Join Date
    May 2003
    Location
    NYC.
    Posts
    46

    Load .JPG in .SWF via .XML

    Trying to: Load .JPG in .SWF via .XML
    the following are the ActionScript and xml info.
    The idea is to load a JPG into a movie clip in the SWF.
    I'm sue its something simple but I can't seem to get this thing to work.
    Any and all help appreciated.
    Also links to related tutorials would be cool too.
    thanks
    James

    ------------
    ActionScript
    ------------

    Images_XML = newXML();
    Images_XML.Load = ("Images.XML");
    Images_XML.onload = Displayimage;
    Images_XML.Ignorewhite = True;
    Function Displayimage(success);{
    If (success == True );
    Rootnode=Images_XML.images.image.childnode.Id[001];
    Imagepath=Images_XML.images.image.childnode.attrib utes.JpegURL;
    Image_area.loadmovie(Imagepath);
    }
    stop();

    -----------
    Images.xml
    -----------

    ?xml version="1.0"?>
    Images>
    Image JpegURL="glib/000.jpg" Id="000">
    Thumbnail JpegURL="glyph/000.jpg" Id="000"> /Thumbnail>
    /Image>
    Image JpegURL="glib/001.jpg" Id="001">
    Thumbnail JpegURL="glyph/001.jpg" Id="001"> /Thumbnail>
    /Image>
    Image JpegURL="glib/002.jpg" Id="002">
    Thumbnail JpegURL="glyph/002.jpg" Id="002"> /Thumbnail>
    /Image>
    /Images>
    Last edited by ROKKPAPA; 05-11-2003 at 07:17 PM.

  2. #2
    Senior Member tupps's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne
    Posts
    2,035
    When you are in the onLoad handler the context of the call is changed. You will find that you can refer to the XML document by using this.mages.image.childnode.Id[001].

    I am guessing that because of the difference in where you are being call your variables are not being assigned. Put a trace statement in your code and see what is happening.

    Thanks

    Luke
    Flash-XML FAQ
    http://www.tupps.com/flash/faq/

  3. #3
    Member
    Join Date
    May 2003
    Location
    NYC.
    Posts
    46

    load jpg....

    Thanks for the reply.
    how ever I dont know what the/a trace element is.
    nor do I understand the rest of the reply.
    I came by the info i've used so far by looking at scripts and tutorials on Flashkit.com but havn't fully grasped all the aspects yet. This has been a crash course weekend of learning for me; so A bit more clearity would be great.
    Thanks Again
    James

  4. #4
    Senior Member tupps's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne
    Posts
    2,035
    OK,

    The trace statement is the first step to debugging and 'seeing' what your code is doing. The basic structure is:

    trace("My Value is: " + myValue);

    In the output window you will see:

    My Value is: 27

    (assuming myValue is set to 27).

    As for scope basically variables that you program with are available to certain blocks of code but not to others. Depending on the environment this can be anything from all global (typical of early basic languages) to all local (typical of Object Oriented languages). Most languages end up somewhere in between but most languages now require you to specify your variables and take extra steps to allow large usage than just local.

    Now with flash any code you have written should have access to any variables declared in its own function, as well as any functions declared in the same code block (eg code window). This works most of the time like this. However with an XML call the call to your onLoad function is made by the flash XML parser once the XML has been loaded and parsed (which can take some time if you have a slow web server/internet connection). This means that while all your other code is called at once this is actually called outside the other code, so all the variables etc are not initialised.

    Hope this clears the issue up a little bit. I am sure it is still going to take some time to get this sorted.

    Thanks

    Luke
    Flash-XML FAQ
    http://www.tupps.com/flash/faq/

  5. #5
    Member
    Join Date
    May 2003
    Location
    NYC.
    Posts
    46

    load jpg....

    I do appreciate your help, how ever I think your providing a rather complex answer to a rather simple question; to someone that by his own admission is trying to marathon before he can walk.

    namely...
    Am I even using the correct syntax in my actionscript?
    If my xml file is named "Images.xml" am I correct in using "Images_XML" to identify it?
    Is the following the correct structure and syntax for what I am trying to achieve?

    Images_XML = newXML();
    Images_XML.Load = ("Images.XML");
    Images_XML.onload = Displayimage;
    Images_XML.Ignorewhite = True;
    Function Displayimage(success);{
    If (success == True );
    Rootnode=Images_XML.images.image.childnode.Id[001];
    Imagepath=Images_XML.images.image.childnode.attrib utes.JpegURL;
    Image_area.loadmovie(Imagepath);
    }
    stop();



    I feel fairly secure in this section,

    Images_XML = newXML();
    Images_XML.Load = ("Images.XML");
    Images_XML.onload = Displayimage;
    Images_XML.Ignorewhite = True;
    Function Displayimage(success);{
    If (success == True );



    But is this section correct?

    Rootnode=Images_XML.images.image.childnode.Id[001];
    Imagepath=Images_XML.images.image.childnode.attrib utes.JpegURL;
    Image_area.loadmovie(Imagepath);

    for calling up the image file from here?
    -----------
    Images.xml
    -----------

    ?xml version="1.0"?>
    Images>
    Image JpegURL="glib/000.jpg" Id="000">
    Thumbnail JpegURL="glyph/000.jpg" Id="000"> /Thumbnail>
    /Image>
    Image JpegURL="glib/001.jpg" Id="001">
    Thumbnail JpegURL="glyph/001.jpg" Id="001"> /Thumbnail>
    /Image>
    Image JpegURL="glib/002.jpg" Id="002">
    Thumbnail JpegURL="glyph/002.jpg" Id="002"> /Thumbnail>
    /Image>
    /Images>

    If not then what is the proper syntax?

    I'm sure that my problem lays within here:

    Rootnode=Images_XML.images.image.childnode.Id[001];
    Imagepath=Images_XML.images.image.childnode.attrib utes.JpegURL;
    Image_area.loadmovie(Imagepath);

    So what part of this is wrong?

    Were and how would I use:

    trace("My Value is: " + myValue);
    were would I place it in the script?
    What values would I apply and were?
    something like:

    trace("Id[001]: " + JpegURL);

    not sure if I mentioned, I'm not a code person by any stretch of the imagination; I'm a commercial photographer in NYC, so please bare with me as I stumble through this.
    Thanks

    James
    Last edited by ROKKPAPA; 05-12-2003 at 09:56 PM.

  6. #6
    Senior Member tupps's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne
    Posts
    2,035
    Ok this section:

    If (success == True );
    Rootnode=Images_XML.images.image.childnode.Id[001];
    Imagepath=Images_XML.images.image.childnode.attrib utes.JpegURL;
    Image_area.loadmovie(Imagepath);


    should be:

    If (success == True ){
    Rootnode=Images_XML.images.image.childnode.Id[001];
    Imagepath=Images_XML.images.image.childnode.attrib utes.JpegURL;
    Image_area.loadmovie(Imagepath);
    }

    Note curly brackets.

    The best way to check the syntax of your XML is to load it in Mozilla 1.3+ or IE 5+. If it is correct then the XML will receive syntax highlighting. Otherwise an error will be reported.

    As for the trace statement I would use it like this:

    If (success == True ){
    Rootnode=Images_XML.images.image.childnode.Id[001];
    trace("Rootnode: " + Rootnode);
    Imagepath=Images_XML.images.image.childnode.attrib utes.JpegURL;
    trace("Imagepath: " + Imagepath);
    Image_area.loadmovie(Imagepath);
    }

    This should output both these statements onto the output console, and give you immediate feedback about whether things are working or not.

    Thanks

    Luke
    Flash-XML FAQ
    http://www.tupps.com/flash/faq/

  7. #7
    Member
    Join Date
    May 2003
    Location
    NYC.
    Posts
    46

    load jpg....

    ok, I've made the changes.
    actionscript now looks like this:

    Images_XML = newXML();
    Images_XML.Load = ("Images.XML");
    Images_XML.onload = Displayimage;
    Images_XML.Ignorewhite = True;
    Function Displayimage(success);{
    If (success == True ){
    Rootnode=Images_XML.images.image.childnode.Id[001];
    Imagepath=Images_XML.images.image.childnode.attrib utes.JpegURL;
    Image_area.loadmovie(Imagepath);
    }
    stop();




    and I get a box that pops up giving these errors:


    Scene=Scene 1, Layer=Layer 1, Frame=1: Line 5: ';' expected
    Function Displayimage(success);{

    Scene=Scene 1, Layer=Layer 1, Frame=1: Line 6: ';' expected
    If (success == True ){

    Scene=Scene 1, Layer=Layer 1, Frame=1: Line 5: Statement block must be terminated by '}'
    Function Displayimage(success);{

    Scene=Scene 1, Layer=Layer 1, Frame=1: Line 11: Syntax error.
    stop();


    when I change it to:

    Images_XML = newXML();
    Images_XML.Load = ("Images.XML");
    Images_XML.onload = Displayimage;
    Images_XML.Ignorewhite = True;
    Function Displayimage(success);{
    If (success == True );{
    Rootnode=Images_XML.images.image.childnode.Id[001];
    Imagepath=Images_XML.images.image.childnode.attrib utes.JpegURL;
    Image_area.loadmovie(Imagepath);
    }
    }
    stop();



    I get this error:

    Scene=Scene 1, Layer=Layer 1, Frame=1: Line 5: ';' expected
    Function Displayimage(success);{


    So i'm getting closer.
    I've emailed you direct links to the test URL and the directory for the .FLA
    I've also picked up a couple of flash / XML books today.
    "I refuse to let this thing get the better me."
    thanks
    James

  8. #8
    Senior Member Jaffasoft's Avatar
    Join Date
    Apr 2001
    Location
    On Travel
    Posts
    1,588
    ROKKPOPA

    Looks as though you have just got a couple of typo's in your code. Some capitals your using in the 'Function, type it ,'function'. And i noticed a ; before the curlies ;{ it should be {. And the if is the only other thing i think i seen , it should be if not If. Just watch your capitals a bit.

    //all i did was test it in the first frame for errors
    //this one came thru with no errors!!

    Images_XML = newXML();
    Images_XML.Load = ("Images.XML");
    Images_XML.onload = Displayimage;
    Images_XML.Ignorewhite = True;
    function Displayimage(success){
    if (success == true ){
    Rootnode=Images_XML.images.image.childnode.Id[001];
    Imagepath=Images_XML.images.image.childnode.attrib utes.JpegURL;
    Image_area.loadmovie(Imagepath);
    }
    }

  9. #9
    Member
    Join Date
    May 2003
    Location
    NYC.
    Posts
    46

    load jpg....

    Well now i'm at a complete loss.
    I've made the changes and get no errors; however I also don't get an image.
    could the problem be here?

    Rootnode=Images_XML.images.image.childnode.Id[001];
    Imagepath=Images_XML.images.image.childnode.attrib utes.JpegURL;
    Image_area.loadmovie(Imagepath);

    Id[001] & JpegURL are attributes of image childnode.

    image JpegURL="glib/001.jpg" Id="001">
    /image>



    James
    Last edited by ROKKPAPA; 05-19-2003 at 04:52 PM.

  10. #10
    Senior Member Jaffasoft's Avatar
    Join Date
    Apr 2001
    Location
    On Travel
    Posts
    1,588
    Ok im going to have a go at this , it mite be a stab in the dark. But try this.

    on (press) {
    Rootnode=Images_XML.images.image.childnode.Id[001];
    Imagepath=Images_XML.images.image.childnode.attrib utes.JpegURL;
    Image_area.loadMovie(Imagepath,"nameOfMcWhereImage LoadsInto");
    }

    You need to write the name of the mc its loading into in the load movie brackets as well. I have a xml load images exp if you want it??
    I can zip it up if you want.

  11. #11
    Member
    Join Date
    May 2003
    Location
    NYC.
    Posts
    46

    load jpg....

    the thing is.......
    there is no " on (press) { "
    the whole idea is for the image to load into the movie clip when the .SWF is loaded.

    yes I'll gladly except the .fla you have to offer.
    thanks
    James

  12. #12
    Senior Member Jaffasoft's Avatar
    Join Date
    Apr 2001
    Location
    On Travel
    Posts
    1,588
    Just take the on press code out.
    Attached Files Attached Files

  13. #13
    Member
    Join Date
    May 2003
    Location
    NYC.
    Posts
    46

    load jpg....

    here are the files I'm working with.
    james
    Attached Files Attached Files

  14. #14
    Member
    Join Date
    May 2003
    Location
    NYC.
    Posts
    46

    load jpg....

    Bump.
    still looking to get this thing to work!

  15. #15
    Senior Member bs_grewal's Avatar
    Join Date
    Dec 2002
    Posts
    548

    hi

    Thanks
    Baljit Singh Grewal
    Click here to email me
    Messengers: baljit@bsgrewal.com

  16. #16
    Member
    Join Date
    May 2003
    Location
    NYC.
    Posts
    46

    load jpg....

    Just as a side note, I got this far with my actionscript by working with existing scripts found on flashkit.com and a number of others; and the 4 flash MX books sitting here.
    Since these scripts worked with no problem and the scripting I've done is only a slight derivation of those it would make sense that the path I'm on should be correct. perhaps the parsing of the xml is off, or the syntax is wrong, but in theory this thing should be do able.

  17. #17
    Member
    Join Date
    May 2003
    Location
    NYC.
    Posts
    46

    Got it to work!!

    below is the working code for those that want it.
    However i'm still tryingto get it to call the .jpg by just the "Id" attribute. any suggestions?
    thanks to all for the help.
    James
    p.s. yes this is a hack of a found script.
    --------------
    actionscript
    --------------
    images_xml = new XML();
    images_xml.onLoad = ViewImage;
    images_xml.load("images.xml");
    images_xml.ignoreWhite = true;
    function ViewImage(success) {
    if (success == true) {
    rootNode = images_xml.firstChild;
    Image = rootNode.firstChild;
    updateImage(Image);
    }
    }
    function updateImage(Image) {
    imagePath = Image.attributes.jpegURL;
    image_area.loadMovie(imagePath);
    }

    -----
    XML
    -----
    ?xml version="1.0"?>

    Images>
    image Id="000" jpegURL="images/image1.jpg"> /image>
    image Id="001" jpegURL="images/image2.jpg"> /image>
    image Id="002" jpegURL="images/image3.jpg"> /image>

    Images>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center