以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 精华版 』  (http://bbs.xml.org.cn/list.asp?boardid=37)
----  [03060]ASP+Flash+XML的小作品  (http://bbs.xml.org.cn/dispbbs.asp?boardid=37&rootid=&id=7886)


--  作者:yuji1998
--  发布时间:5/27/2004 1:39:00 AM

--  [03060]ASP+Flash+XML的小作品
[原作者:forwar]
             [疑问点击]    [意见箱]

我将举一个我以前制作的ASP+Flash+XML的小作品作为实例。这个小作品也将给大家提供下载源代码进行研究。(这个模型的研究要强烈的感谢ZAS的支持!,在此鸣谢!)

先看看源文件的XML初始化情况,以下是部分代码,我将对其中比较重要的几个部分来说说怎么读取动态的XML文件,里面涉及到一些XML对象的基本方法和属性,大家可以练习一下。遇到一些方法属性的时候我就不再声明了,请参照Macromedia的帮助文件。
myXML   =   new   XML();//构造XML对象
System.useCodePage   =   true;//支持中文码制
myXML.load("http://127.0.0.1/xml/showit.asp?page="'' target="_blank" >http://127.0.0.1/xml/showit.asp?page=";+page+"&temp="+Math.floor(Math.random()*1234567890));
/*--------------------------------------------------------------------
----------------------------------------------------------------------
这里是一个小小的诀窍:myXML.load("一个动态的地址")。这样可以防止读取缓存。众所周知
如果这次我们请求的地址和上次相同的话,浏览器就会检查缓存,为了防止这种现象我们把
地址的后面加上一个随机数page=+page+"&temp+Math.floor(Math.random()*1234567890))";
Math.random()函数将产生一个大于0小于1的随机数,这个随机数*1234567890,之后再用
Math.floor()   函数取其下限值,这样我们每次访问的地址重复的可能性基本是微乎其微的
缓存的问题就解决了,就比如
第一次访问的地址:http://127.0.0.1/xml/showit.asp?page=1&temp=334526384
而第二次访问的地址就是:   http://127.0.0.1/xml/showit.asp?page=1&temp=664636251
请求的都是显示第一页,而浏览器不会调用缓存。
----------------------------------------------------------------------
---------------------------------------------------------------------*/
myXML.onLoad   =   checkLoad;//当MyXML.onLoad事件被触发的时候,则执行checkLoad事件
function   checkLoad(success)   {//定义checkLoad事件
   if   (success)   {//如果是success状态
         readata();//执行readata()函数
   }
      function   readata()   {//再定义readata函数
                        _root.preurl   =   new   Array   ();//构造数组preurl
                        _root.physurl   =   new   Array   ();//构造
                        _root.filename   =   new   Array   ();//构造
                        _root.filetype   =   new   Array   ();//构造
      _root.comm=new   Array();//构造
         _root.addtime=new   Array();//构造
         _root.filename=new   Array();//构造
         _root.viewed=new   Array();//构造
                        skiphead.ignoreWhite   =   1;//对后面定义的skiphead   这个XML对象忽略空白节点
                        skiphead   =   myXML.firstChild.childNodes[0];//skiphead定义为myXML.firstChildfirstChild.childNodes[0]
      _global.pagemax=myXML.firstChild.childNodes[1].childNodes;//定义一个全局变量_global.pagemax
      
                        parentName   =   skiphead.nodeName;//定义节点名
                        tencontent   =   new   Array   ();//定义数组
                        tencontent   =   skiphead.childNodes;//定义skiphead的节点集数组为tencontent
                        sites   =   new   Array   ();//定义sites为数组
                        sites   =   tencontent;//赋值
                        i   =   0;
                        while   (i   <=   sites.length)   {//一个循环
         if   (sites[i].nodeName   !=   null)   {//如果节点名不为空则……
/*--------------------------------------------------------------------------------
下面的代码就是具体的判断,我就不详细说了。通过这段代码我只想阐述Flash读取动态ASP返回值的例子,相信大家看过之后也会理解的,如果大家对这个小模型感兴趣的话,就请下载模型研究吧   :)                                                
            nowsite   =   sites[i];
                     nowsiteAtt   =   new   Array   ();
                     nowsiteAtt   =   nowsite.attributes;
                     nowsiteId   =   nowsiteAtt.id;
                    strnowsiteId   =   new   String   (nowsiteId);
                     nowsiteIdSimple   =   strnowsiteId.slice(-1);
                     nowsiteIdSimple   =   "site"   +   nowsiteIdSimple;
                     nowsitedata   =   new   Array   ();
                     nowsitedata   =   nowsite.childNodes;
                         j   =   0;
                         while   (j   <=   nowsitedata.length)   {
               
                                 if   (nowsitedata[j].nodeName   !=   null)   {
                  
                                      switch   (nowsitedata[j].nodeName)   {
                                                              case   "filetype"   :   
                 _root.filetype[nowsiteIdSimple]   =   nowsitedata[j].firstChild.nodevalue;
                                                            break;
                                                                                               case   "filename"   :   
               _root.filename[nowsiteIdSimple]   =   nowsitedata[j].firstChild.nodevalue;
                        break;
case   "pre"   :   
               _root.preurl[nowsiteIdSimple]   =   nowsitedata[j].firstChild.nodevalue;
                        break;
case   "physurl"   :   
              _root.physurl[nowsiteIdSimple]   =   nowsitedata[j].firstChild.nodevalue;
                        break;
case   "comm"   :   
             _root.comm[nowsiteIdSimple]   =   nowsitedata[j].firstChild.nodevalue;
                        break;
case   "addtime"   :   
             _root.addtime[nowsiteIdSimple]   =   nowsitedata[j].firstChild.nodevalue;
                        break;
case   "viewed"   :   
             _root.viewed[nowsiteIdSimple]   =   nowsitedata[j].firstChild.nodevalue;
                                                                           
                  }
               }
                                                            j++;
                                                   
            
            }
                                    }
                                    i++;

            }

            
   }
      
      }


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
78.125ms