如何使用ActionScript提取DOM元素?

时间:2016-04-20 16:19:31

标签: javascript actionscript-3 flash dom actionscript

我正在尝试从使用开放式跨域策略的网站中提取DOM元素。从ActionScript文档here看起来它想要一个.xml文件的端点。有没有办法拉出DOM数据并将其写回文件给我?这是我到目前为止所拥有的。

package {
 import flash.display.Sprite;
 import flash.events.*;
 import flash.net.URLRequestMethod;
 import flash.net.URLRequest;
 import flash.net.URLLoader;
 import flash.text.TextField;
 import flash.text.TextFieldAutoSize;
 import flash.xml.*;
 import flash.events.IOErrorEvent;

 public class CrossDomain extends Sprite {
   private var xmlTextField:TextField = new TextField();
   private var externalXML:XML;
   private var loader:URLLoader;

   public function readingData() {
   // URL from where the data is to be retrieved
   var readFrom:String = "http://www.site1.com/datawithDOMstuff";
   var readRequest:URLRequest = new URLRequest(readFrom);
   var getLoader:URLLoader = new URLLoader();


   try {
   getLoader.load(readRequest);
 } catch (error:SecurityError)
 {
 trace ("A yo error.");
}
 getLoader.addEventListener(IOErrorEvent.IO.ERROR, errorHandler);
 getLoader.addEventListener(Event.COMPLETE, eventHandler);

 xmlTextField.x = 10;
 xmlTextField.y = 10;
 xmlTextField.background = true;
 xmlTextField.autoSize = TextFieldAutoSize.LEFT;

 addChild(xmlTextField);
 }


 private function eventHandler(event:Event):void {
   try {
    externalXML = new XML(getLoader.data);
    readNodes(externalXML);
   } catch (error:Error) {
    trace("Error loading URL: " + error);
   }
  }



  private function readNodes(node:XML):void {

    for each (var element:XML in node.elements()) {
        xmlTextField.appendText(element.attributes()[0] + "\n");

        readNodes(element);
    }
    var sendTo:String = "http://site2.com/writefilebacktome"
    var sendRequest:URLRequest = new URLRequest(sendTo);
    sendRequest.method = URLRequestMethod.POST;
    sendRequest.element = event.target.data;
    var sendLoader:URLLoader = new URLLoader();
    try {
     sendLoader.load(sendRequest);
    } catch (error:Error) {
     trace("Error loading URL: " + error);
    }

}

private function errorHandler(e:IOErrorEvent):void {
xmlTextField.text = "Had problem loading the XML File.";
    }
  }
}

0 个答案:

没有答案