Skip to main content
May 31, 2016
Question

How to make a MovieClip from image thats loading from XML

  • May 31, 2016
  • 2 replies
  • 835 views

How to make a MovieClip from an image thats loading from XML? and how to put an images in a designated place on a flash worksheet , and turn it into movie clip or button?

AS3

var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE,f);
urlLoader.load(new URLRequest("images.xml"));

var ldr:Loader = new Loader();

function f(e:Event){
    var xml = XML(urlLoader.data);
    ldr.load(new URLRequest(xml.image.attribute("url")));
}

xml
<images>
<image url="image1.jpg"/>
</images>

@kglad

This topic has been closed for replies.

2 replies

May 31, 2016

Get error :

Code:

kglad
Community Expert
Community Expert
May 31, 2016

don't use the same function name.

and if you copy and paste code instead of embedding a screenshot of it, i can edit your code to show exactly how to do that.

May 31, 2016

okey, i'm sorry

import flash.net.URLLoader;

import flash.events.Event;

import flash.net.URLRequest;

import flash.display.Loader;

import flash.events.MouseEvent;

stop();

var urlLoader:URLLoader=new URLLoader();

urlLoader.addEventListener(Event.COMPLETE,f);

urlLoader.load(new URLRequest("file.xml"));

var ldr:Loader=new Loader();

var mc:MovieClip=new MovieClip();

mc.addEventListener(MouseEvent.CLICK, nextpage);

function nextpage(event:MouseEvent)

{

    gotoAndStop(1,"profil");

}

addChild(ldr);

function f(e:Event)

{

    var xml=XML(urlLoader.data);

    ldr.load(new URLRequest(xml.image.attribute("url")));

}

function f(e:Event):void

{

    mc.addChild(ldr);

}

kglad
Community Expert
Community Expert
May 31, 2016

you can't turn the loader to a movieclip but you can add the loader to a movieclip parent using addChild:

var mc:MovieClip=new MovieClip();

function f(e:Event):void{

mc.addChild(ldr);

}

May 31, 2016

Can i add this code after that?

mc.addEventListener(MouseEvent.CLICK, nextpage);

function nextpage(event:MouseEvent)

{

    gotoAndStop(1,"Scene 2");

}