A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Best way change xml file

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    16

    Best way change xml file

    Hello, i trie to change dynamically loaded xml file. Example: default loaded xml file is books.xml, now if i push button named CDs then it loads cd.xml. How can i do this? I haved tried and triend on nothing worked. Do i need to use listener and trace? I hope somebody can make some example. I have to files Script.as and Page.swf

    Script.as file
    Actionscript Code:
    package {

        import flash.display.Sprite;
        import flash.display.MovieClip;
        import flash.display.DisplayObject;
        import flash.display.SimpleButton;
        import flash.display.StageAlign;
        import flash.display.StageDisplayState;
        import flash.display.StageScaleMode;
        import flash.display.Bitmap;
        import flash.display.Loader;
        import flash.geom.Rectangle;
        import flash.media.Sound;



        import flash.events.*;

        import flash.text.TextField;
        import flash.text.TextFormat;
        import flash.text.TextFieldAutoSize;

        import flash.media.SoundChannel;
        import flash.media.SoundTransform;

        import flash.net.URLLoader;
        import flash.net.URLRequest;
        import flash.net.navigateToURL;
        import flash.net.URLVariables;
        import flash.net.URLRequestMethod;


        import flash.system.Capabilities;
        import flash.utils.Timer;

        import flash.media.SoundChannel;
        import flash.media.SoundTransform;

        import caurina.transitions.Tweener;
        import caurina.transitions.properties.FilterShortcuts;

        import tm.com.*;


        public class Main extends MovieClip {

            private var quality:Number = 1;

            private var _root = root as MovieClip;
            private var _parent = parent as MovieClip;

            public var logoPic1X:Number = 0;
            public var logoPic1Y:Number = 0;
            public var logoPic2X:Number = 0;
            public var logoPic2Y:Number = 0;
           
            private var pcent:Number;
           
            private var xmlURL:String = 'xml/books.xml';
            private var titleFormXML:String="xml/conf.xml";

            private var pcentXML:Number;
            public var websiteXML:XML;
            public var confXML:XML;
            public var xmlLoader:URLLoader;

            public var linkPage:Number = 100;
            public var numGallImages:Number = 0;
            public var k1:Number = 1;
            public var ACT:Number = 0;
            public var animDesc:Number = 1;
           

            private var rectangle:Rectangle;
            private var rectangle_X:Rectangle;
            private var clicked:DisplayObject;
            private var kk:Number;
           
            private var kk_X:Number;
           
            public var picURL:URLRequest;
            public var picLoader:Loader;
           
            public var xmlFormLoader:URLLoader;
            public var request:URLRequest;
            public var variables:URLVariables;
            public var formItems:Array = [];
           
            private var soundTitle:Boolean = true;
            private var closeSplash:Boolean = false;
           
            private var st:SoundTransform = new SoundTransform();
            public var animation:Boolean = true;
            public var openSpashPage:Boolean = false;
           
           



                    public function Main() {
                stage.scaleMode=StageScaleMode.NO_SCALE;
                stage.align=StageAlign.TOP_LEFT;
               
                addEventListener(Event.ENTER_FRAME, appLoadingHandler);
                    function appLoadingHandler( event:Event ):void {
                        if (stage) {
                            var bytesTotal = stage.loaderInfo.bytesTotal;
                            var bytesLoaded = stage.loaderInfo.bytesLoaded;
                            loadingMovie.gotoAndStop(Math.floor(bytesLoaded*100/bytesTotal));
                            //loadingMovie.loaderText.htmlText ="LOADING "+Math.floor(bytesLoaded * 100 / bytesTotal) + "%"
                            loadingMovie.loaderText.htmlText =Math.floor(bytesLoaded * 100 / bytesTotal) + "%"
                            //loadingMovie.loaderText.autoSize = TextFieldAutoSize.CENTER;
                           
                        if ( bytesLoaded >= bytesTotal) {
                            removeEventListener(Event.ENTER_FRAME, appLoadingHandler);
                            _root.gotoAndStop(2);
                            loaderXML();
                        }
                    }
                }
            }
            public function loaderXML() {

                xmlLoader = new URLLoader();

                xmlLoader.addEventListener(Event.COMPLETE, showXML);
                xmlLoader.addEventListener(ProgressEvent.PROGRESS, traceLoaderXML);

                xmlLoader.load(new URLRequest(xmlURL));

                XML.ignoreWhitespace = true;


                function traceLoaderXML(eventXML:ProgressEvent) {

                    pcentXML = int(eventXML.bytesLoaded / eventXML.bytesTotal * 100);

                    if (pcentXML==100) {
                       
                       
                    }
                }
                function showXML(e:Event):void {
                    _root.gotoAndPlay(3);
                    websiteXML = new XML(e.target.data);
                    popupFunction();
                }
            }
           
           
            public function settingsText(textField:TextField, nameText:String) {

                textField.htmlText = websiteXML.settings.item.(@name == nameText);
                textField.addEventListener( TextEvent.LINK, textLinkClick );

            }
            public function popupFunction() {

                addEventListener( 'switchPage', onSwitchPage);
                addEventListener( 'switchPopup', onSwitchPopup);
                addEventListener( 'privacy', onSwitchPrivacy);
               
                addEventListener( 'privacy', onSwitchPrivacy);
                addEventListener( 'fullScren', fullScrenButton);
                //addEventListener( 'logoLink', logoClic);
               
               

                function onSwitchPage(event:TemplateEvent):void {
                    var targetPage:Number = event.info[0]
                   
                    _root.subMenu['itemButton_' + _root.linkPage].gotoAndPlay('s2');
                   
                    _root.linkPage = targetPage;
                   
                    _root.subMenu['itemButton_' + _root.linkPage].gotoAndPlay('s1');
                    _root.allContent.play();
                }
                function onSwitchPopup(event:TemplateEvent):void {
                    var targetPage:Number = event.info[0];
                   
                    popapPage.popapTitle = websiteXML.pages.titlePage[_root.linkPage].pagePopup.popup[targetPage].item.(@name == "title");
                    popapPage.popapInfo = websiteXML.pages.titlePage[_root.linkPage].pagePopup.popup[targetPage].item.(@name == "linkText");
                   
                    popapPage.gotoAndPlay('open');         
               
                }
                function onSwitchPrivacy(event:TemplateEvent):void {
                    var targetPage:Number = event.info[0];
                   
                    popapPage.popapTitle = websiteXML.section.(@name == "privacyPolicy").item.(@name == "pageTitle");
                    popapPage.popapInfo = websiteXML.section.(@name == "privacyPolicy").item.(@name == "pageText");
                   
                    popapPage.gotoAndPlay('open');
                   
               
                   
                }
               
               
    .......

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You just load the second XML file the same way you have loaded the first one using the same functions.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    16
    Thank u for replay but i mean that i can change xml files with button push not to load two xml files

  4. #4
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Do you have two xml file strings in your code somewhere?
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  5. #5
    Junior Member
    Join Date
    Feb 2011
    Posts
    16
    Hello,
    Actually no. i need to change this that i can use two xml files. Like if i push the CD button it loading cd.xml and push BOOKS it loading books.xml. XML file content are books and cd list.

  6. #6
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Then you need to load the xml file at runtime to get access to it. Do it using the same function you used loading the first file.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

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