Go Back   kirupaForum > Flash > ActionScript 1.0/2.0

Reply
 
Thread Tools Display Modes
Old 11-16-2009, 09:14 AM   #1
shannonDB
Registered User
*SOLVED* using XML to display an image

Hi,

I'm having a hard time wrapping my head around XML, in particular using XML to place an image on the stage.

I've got some code which I've appropriated from a tutorial, which creates a nice XML driven menu - And I would like to adapt it so that when I click on a menu item it displays a JPG (it currently calls up defined labels on my timeline, which is not really what I'm looking for)

I'm really hoping somebody can help me out with this, as trawling google hasn't really given me the simple answer I was looking for (lots of XML galleries tutorials, but I couldn't find an easy tutorial to display 1 image)

Code:
code changed, and updated in my second post below
If anyone could spare a moment to help me understand how I can make this happen with this code I'd be very appreciative.
cheers

Last edited by shannonDB; 11-17-2009 at 08:24 AM..
shannonDB is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 11-17-2009, 12:49 AM   #2
shannonDB
Registered User
using some help from another forum, I've made a step closer to what i was looking for, but I'm still not quite there..

Currently with the code below, instead of displaying the image, I get the name of the image displaying in the OUTPUT window of Flash (and not image in my image holder)

(the code creates an XML driven menu - The menu itself works fine, but what I want it to do is is when a menu item is clicked, it should place an image into an MC image holder.
I have created an MC on the stage with the instance name imageHolder)

Hoping somebody could take a look and let me know where I have gone wrong..

thanks in advance..

Here is my XML
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<menu>
<menu buttonName = "item 1" imgName="1.jpg"/>
<menu buttonName = "item 2" imgName="2.jpg"/>
<menu buttonName = "item 3" imgName="3.jpg"/>
</menu>
here is my AS2:
Code:
pages.stop();
ready = false;
speed = 5;
xStart = 5;
yStart = 48;
bWidth = 82;
bHeight = 18;
var menuXml = new XML();
//loadXml("../assets/xml-menu/menu.xml");
loadXml("test.xml");
function loadXml(file:String) {
    menuXml.ignoreWhite = true;
    menuXml.onLoad = loadMapData;
    menuXml.load(file);
    function loadMapData() {
        for (var i = 0; i<this.firstChild.childNodes.length; i++) {
            var bn = this.firstChild.childNodes[i].attributes.buttonName;
            var b = _root.attachMovie("button", bn, i);
    var img = this.firstChild.childNodes[i].attributes.imgName;
    b.link = img;
            b._x = xStart;
            b._y = yStart+(bHeight*i);
            b.txt = bn;
            b.onPress = function() {
    trace(this.link);
    // imageHolder.loadMovie(this.link);  // load to empty movieclip
                pages.gotoAndStop(this.txt);
                pages.heading = this.txt;
                target = this._y;
            };
            /*b.onRollOver = function() {
            this.gotoAndStop(2);
            };
            b.onRollOut = function() {
            this.gotoAndStop(1);
            };*/
        }
    }
}
var c = this.attachMovie("current", "current", 100);
var d = this.attachMovie("draw", "draw", 101);
d._x = 5;
d._y = 160;
c._x = xStart+bWidth;
c._y = 200;
target = yStart;
this.onEnterFrame = function() {
    if (ready) {
        current._y += (target-current._y)/speed;
    }
};

Last edited by shannonDB; 11-17-2009 at 12:55 AM..
shannonDB is offline   Reply With Quote
Old 11-17-2009, 08:23 AM   #3
shannonDB
Registered User
SUCCESS!!!

I reviewed my code again, and realised the answer was staring me in the face the whole time..

I now have a much better understanding on how XML works..

my working code is now as follows:

Code:
pages.stop();
ready = false;
speed = 5;
xStart = 5;
yStart = 48;
bWidth = 82;
bHeight = 18;
var menuXml = new XML();
//loadXml("../assets/xml-menu/menu.xml");
loadXml("menu.xml");
function loadXml(file:String) {
    menuXml.ignoreWhite = true;
    menuXml.onLoad = loadMapData;
    menuXml.load(file);
    function loadMapData() {
        for (var i = 0; i<this.firstChild.childNodes.length; i++) {
            var bn = this.firstChild.childNodes[i].attributes.buttonName;
            var b = _root.attachMovie("button", bn, i);
            var img = this.firstChild.childNodes[i].attributes.imgName;
            b.link = img;
            b._x = xStart;
            b._y = yStart+(bHeight*i);
            b.txt = bn;
            b.onPress = function() {
                imageHolder.loadMovie(this.link);  // load to empty movieclip
                pages.gotoAndStop(this.txt);
                pages.heading = this.txt;
                target = this._y;
            };
            /*b.onRollOver = function() {
                        this.gotoAndStop(2);
                        };
                        b.onRollOut = function() {
                        this.gotoAndStop(1);
                        };*/
        }
    }
}
var c = this.attachMovie("current", "current", 100);
var d = this.attachMovie("draw", "draw", 101);
d._x = 5;
d._y = 160;
c._x = xStart+bWidth;
c._y = 200;
target = yStart;
this.onEnterFrame = function() {
    if (ready) {
        current._y += (target-current._y)/speed;
    }
};
happy days!!
shannonDB is offline   Reply With Quote
Old 11-19-2009, 01:11 AM   #4
rojertwose
Registered User
Thanks for this XML coding actually i am looking this type of code but i have yet some problem..When i execute this coding this not work..what's the problem for this..

Thanks..

__________________
Bluetooth Headset
rojertwose is offline   Reply With Quote
Old 11-23-2009, 02:34 AM   #5
shannonDB
Registered User
Quote:
Originally Posted by rojertwose View Post
Thanks for this XML coding actually i am looking this type of code but i have yet some problem..When i execute this coding this not work..what's the problem for this..

Thanks..
my XML file is named menu.xml, and I've placed it in the root directory with my swf's.

try this tutorial out.. It's where I got my code from, and then adapted it: http://www.flash-game-design.com/fla...-tutorial.html
shannonDB is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:07 PM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com