jeudi 25 février 2016

import from xml to fla error

i have this xml tree

<?xml version="1.0" encoding="UTF-8"?>
<letters>
 <all>
      <explain>
          <word>slope</word>
      </explain>
      <description>
          <definition>a</definition>
      </description>
  </all>

   <all>
      <explain>
          <word>slope2</word>
      </explain>
      <description>
          <definition>b</definition>
      </description>
  </all>
</letters>

i want to get the word as " slope " from xml to button in swf . when i click this button it will get definition as " a " .. i think that i will get word and definition both of them once time but definition will be in textarea and it will be hidden and with click it will be visible .. so i made that but i have a problem .. help me

import flash.events.MouseEvent;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.display.Sprite;
import flash.display.MovieClip;
import fl.controls.TextArea;

stop();
var ChangebtnPosition:int = 50;
var definition:Array = new Array  ;
var MydataAreaPosition:int = 580;

var myLoader:URLLoader= new URLLoader();
myLoader.load(new URLRequest("eL366.xml"));
myLoader.addEventListener(Event.COMPLETE,loadXML);
function loadXML(e:Event)
{
    var myxml:XML = new XML(e.target.data);
    var lenngth:int = myxml.children().length();
    for (var i:int = 0; i < lenngth; i++)
    {
        var btn:MovieClip = ButtonForWord(String(myxml.all.explain[i - 1].word));
        var aTa:TextArea = new TextArea();
        aTa.move(130,MydataAreaPosition);
        aTa.setSize(200, 200);
        aTa.condenseWhite = true;
        aTa.htmlText = String(myxml.all.description[i - 1].definition);
        addChild(aTa);
        aTa.visible = false;
        MydataAreaPosition +=  40;
        btn.x = 165;
        btn.y = 165 + n;
        addChild(btn);
        ChangebtnPosition +=  50;
        btn.addEventListener(MouseEvent.CLICK,aTaShow);
    }
}
function ButtonForWord(label:String):MovieClip
{
    var txt:TextField = new TextField();
    txt.defaultTextFormat = new TextFormat('Cooper Black',20,0x8b3a3a);
    txt.text = label;
    txt.autoSize = TextFieldAutoSize.LEFT;
    txt.background = txt.border = false;
    txt.selectable = false;
    var btn:MovieClip = new MovieClip();
    btn.mouseChildren = false;
    btn.buttonMode = true;
    btn.addChild(txt);
    btn.label = label;
    return btn;
}
function aTaShow()
{
    addChild(aTa);
}

Aucun commentaire:

Enregistrer un commentaire