A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: how do most of you use XML? and quick XML question.

  1. #1
    Senior Member
    Join Date
    Jul 2007
    Posts
    243

    how do most of you use XML? and quick XML question.

    Ive used XML for a while but always used it inside the code, just wondering if it is better practice to load things in a class and then bring in what parts i need to if it doesnt make any difference?

    also i am planning something with xml where a text box displays a child node and then the next node and then the next node with a small animation tween, would i use a for each loop for that?

    ie
    <xml>
    <numbers>
    <one>one</one>
    <two>two</two>
    <three>three</three>
    </numbers>
    </xml>



    thanks
    Dan

  2. #2
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    PHP Code:
    import fl.transitions.Tween;
    import fl.transitions.easing.None;
    import fl.transitions.TweenEvent;

    var 
    counter:Number 0;
    var 
    container:MovieClip;
    var 
    tf:TextField;

    // your XML structure
    var xmlData:XML = <xml>
                        <
    item>
                            <
    description>Whatever</description>
                        </
    item>
                        <
    item>
                            <
    description>Something</description>
                        </
    item>
                        <
    item>
                            <
    description>What?</description>
                        </
    item>
                      </
    xml>;

    stage.scaleMode StageScaleMode.NO_SCALE;
    stage.showDefaultContextMenu false;
    stage.align StageAlign.LEFT;

    init();
    function 
    init():void
    {
        
    // you'd have a load XML function here but for this
        // example I kept the XML inside the .fla; it's much better
        // to have XML loaded dynamically from .xml files than
        // defining the structure manually inside Flash
        
        
    createContainer();
        
    createField();
        
    animate(this.counter);
    }

    function 
    createContainer():void
    {
        
    this.container = new MovieClip();
        
    this.container.alpha 0;
        
    addChild(this.container);
    }

    function 
    createField():void
    {
        
    this.tf = new TextField();
        
    this.tf.width 250;
        
    this.tf.height 100;
        
    this.tf.selectable false;
        
    this.container.addChild(this.tf);
    }

    function 
    animate(counter:Number):void
    {
        
    this.tf.text String(this.xmlData.item[counter].description);
        
        var 
    tween:Tween = new Tween(this.container"alpha"None.easeNone01.5true);
        
    tween.addEventListener(TweenEvent.MOTION_FINISHtweenFadeInFinishHandler);
    }

    function 
    tweenFadeInFinishHandler(event:TweenEvent):void
    {
        
    event.target.removeEventListener(TweenEvent.MOTION_FINISHtweenFadeInFinishHandler);
        
        var 
    timer:Timer = new Timer(15000);
        
    timer.addEventListener(TimerEvent.TIMERtimerHandler);
        
    timer.start();
    }

    function 
    timerHandler(event:TimerEvent):void
    {
        
    event.target.removeEventListener(TimerEvent.TIMERtimerHandler);
        
    event.target.stop();
        
        var 
    tween:Tween = new Tween(this.container"alpha"None.easeNone10.5true);
        
    tween.addEventListener(TweenEvent.MOTION_FINISHtweenFadeOutFinishHandler);
    }

    function 
    tweenFadeOutFinishHandler(event:TweenEvent):void
    {
        
    event.target.removeEventListener(TweenEvent.MOTION_FINISHtweenFadeOutFinishHandler);
        
        if (
    this.counter this.xmlData.item.length() - 1)
        {
            
    this.counter++;
            
    animate(this.counter);
        }




    | Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro |
    WebLog: http://blog.wisebisoft.com/ |
    | Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
    |
    Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/
    | By perseverance the snail reached the ark. |


  3. #3
    Senior Member
    Join Date
    Jul 2007
    Posts
    243
    thanks for the reply, ill study the code in more detail a bit later
    thanks for your help

  4. #4
    Senior Member
    Join Date
    Apr 2008
    Location
    Nottingham, UK
    Posts
    348
    i generally use a standalone xml-based config file. can;t really help with the rest of it though!

    Dan

  5. #5
    Senior Member
    Join Date
    Jul 2007
    Posts
    243
    thanks for that dan_hin, ive stripped it down and added my own things in, one thing i can't find is, as im using math.random to access random nodes in the xml document, but i could have 20 or 150 nodes in there, so instead of math.random*37 for example, how can i multiply it by the number of nodes in the document?
    thanks
    Dan

    never mind, as with most things i figure it out as soon as i pose the question was just Math.random()*this.xmlData.item.length() - 1
    thanks again
    Last edited by danhodkinson; 10-20-2008 at 02:12 PM.

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