-
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
-
trace("AKA: Biro Barna");
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.easeNone, 0, 1, .5, true); tween.addEventListener(TweenEvent.MOTION_FINISH, tweenFadeInFinishHandler); }
function tweenFadeInFinishHandler(event:TweenEvent):void { event.target.removeEventListener(TweenEvent.MOTION_FINISH, tweenFadeInFinishHandler); var timer:Timer = new Timer(1500, 0); timer.addEventListener(TimerEvent.TIMER, timerHandler); timer.start(); }
function timerHandler(event:TimerEvent):void { event.target.removeEventListener(TimerEvent.TIMER, timerHandler); event.target.stop(); var tween:Tween = new Tween(this.container, "alpha", None.easeNone, 1, 0, .5, true); tween.addEventListener(TweenEvent.MOTION_FINISH, tweenFadeOutFinishHandler); }
function tweenFadeOutFinishHandler(event:TweenEvent):void { event.target.removeEventListener(TweenEvent.MOTION_FINISH, tweenFadeOutFinishHandler); 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. |
-
thanks for the reply, ill study the code in more detail a bit later
thanks for your help
-
i generally use a standalone xml-based config file. can;t really help with the rest of it though!
Dan
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|