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
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 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
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.
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?
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
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:
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
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!!
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.
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.
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);
}