Skip to main content
spvr
Inspiring
March 15, 2010
Answered

Creating movieclip buttons through script with xml data?

  • March 15, 2010
  • 1 reply
  • 952 views

The following code showing errors, when I create multi buttons based on xml data. please help me out

package {
    //import flash libraries
    import flash.display.Sprite;
    import flash.events.*;
    import flash.xml.*;
       
    import flash.display.MovieClip;

    public class multibuttons extends Sprite {

        private var xml_loader:URLLoader;
        private var xml_data:XML;

        public function multibuttons() {

            xml_loader=new URLLoader();
            xml_data=new XML();

            xml_loader.load(new URLRequest("buttons.xml"));
            xml_loader.addEventListener(Event.COMPLETE,load_xml);
        }


        public function load_xml(evt:Event):void {
            try {
                xml_data=new XML(evt.target.data);
                trace("XML data Loaded successfully");
                button_xml_list(xml_data);
            } catch (evt:message) {
                trace("XML data Not Loaded");
                trace(evt.error);
            }

        }

        public function button_xml_list(butn_list:XML):void {
            var button_list:XMLList=butn_list.totalbutton.button;
            for each (var button_element:XML in button_list) {
                trace(button_element);
                //box_button is movie clip linkgae
                var create_button:box_button=new box_button();
                create_button.x=50;
                create_button.y=50;
                addChild(create_button);
                create_button.x+=30;
            }

        }

    }


}

This topic has been closed for replies.
Correct answer kglad

Thank you vermuch I got cleared all my errors.Finally i got some problem. How to assign button array.and how to get button in stage?

public function button_xml_list(butn_list:XML):void {
            var button_list:XMLList=butn_list.child(0);
            for each (var button_element:XML in button_list) {
            //box_button is movie clip linkgae
            var create_button:box_button=new box_button();
            create_button.x=50;
            create_button.y=50;
            addChild(create_button);
            create_button.x+=30;
            }


if multibuttons is your document class, your buttons will be added to the stage.  but they'll all be added to the same x,y so

you'll only see one.

1 reply

kglad
Community Expert
Community Expert
March 15, 2010

click file/publish settings/flash and tick "permit debugging".  then highlight the line of code indicated in the error message and paste the error message here.

spvr
spvrAuthor
Inspiring
March 15, 2010

I got some following errors:

1046: Type was not found or was not a compile-time constant: URLLoader.

1180: Call to a possibly undefined method URLLoader.

1180: Call to a possibly undefined method URLRequest.

1046: Type was not found or was not a compile-time constant: message.

kglad
Community Expert
Community Expert
March 15, 2010

import those classes.  and, change

catch (evt:message)

to

catch (evt:Error)