zoukankan      html  css  js  c++  java
  • silverlight如何使用 Downloader 物件非同步下載各式資源

    if (!window.demoVideo21)
        window.demoVideo21 
    = {};

    demoVideo21.Scene 
    = function() 
    {
    }


    demoVideo21.Scene.prototype 
    =
    {
        handleLoad: 
    function(plugIn, userContext, rootElement) 
        
    {
            
    this.plugIn = plugIn;
            
            
    // Sample button event hookup: Find the button and then attach event handlers
            this.button = rootElement.children.getItem(0);    
            
            
    this.button.addEventListener("MouseEnter", Silverlight.createDelegate(thisthis.handleMouseEnter));
            
    this.button.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(thisthis.handleMouseDown));
            
    this.button.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(thisthis.handleMouseUp));
            
    this.button.addEventListener("MouseLeave", Silverlight.createDelegate(thisthis.handleMouseLeave));
        }
    ,
        
        
    // Sample event handlers
        handleMouseEnter: function(sender, eventArgs) 
        
    {
            
    // The following code shows how to find an element by name and call a method on it.
            var mouseEnterAnimation = sender.findName("mouseEnter");
            mouseEnterAnimation.begin(); 
        }
    ,
        
        handleMouseDown: 
    function(sender, eventArgs) 
        
    {
            
    var mouseDownAnimation = sender.findName("mouseDown");
            mouseDownAnimation.begin(); 
        }
    ,
        
        handleMouseUp: 
    function(sender, eventArgs) 
        
    {
            
    var mouseUpAnimation = sender.findName("mouseUp");
            mouseUpAnimation.begin(); 
            
            
    // Put clicked logic here
            var plugIn=sender.getHost();
            
            
    var dl=plugIn.createObject("Downloader");
            dl.addEventListener(
    "Completed",onCompleted);
            dl.addEventListener(
    "DownloadProgressChanged",onDownloadProgressChanged);
            dl.addEventListener(
    "DownloadFailed",onDownloadFailed);
            
            
    //下载请求
            dl.open("get","test.zip");
            
    //开始下载
            dl.send();
        }
    ,
        
        handleMouseLeave: 
    function(sender, eventArgs) 
        
    {
            
    var mouseLeaveAnimation = sender.findName("mouseLeave");
            mouseLeaveAnimation.begin(); 
        }

    }

    function onCompleted(sender, EvengArgs)
    {
        
    var music=sender.findName("Music");
        music.setSource(sender, 
    "summer.Wma");
        
        
    var movie=sender.findName("Movie");
        movie.setSource(sender, 
    "SampleVideo.wmv");
        
        
    var img=sender.findName("Image");
        img.setSource(sender, 
    "downloader.jpg");
        
        
    var strJs=sender.GetResponseText("js.js");
        eval(strJs);
        
        
    var xaml=sender.GetResponseText("asdf.xaml");
        
    var obj=sender.getHost().content.createFromXaml(xaml,true);
        
    var rootCanvas=sender.findName("rootCanvas");
        rootCanvas.children.add(obj);
    }

    function onDownloadProgressChanged(sender, EvengArgs)
    {
        
    var txtProgress=sender.findName("txtProgress");
        
    var p=Math.floor(sender.downloadProgress*100);
        txtProgress.text
    =p+" %";
    }

    function onDownloadFailed(sender, EvengArgs)
    {
        alert(
    "falied"+"\n code"+sender.status+"\n text:"+sender.statusText);
    }
  • 相关阅读:
    Java NIO开发需要注意的陷阱(转)
    Java Nio注意事项
    NIO的介绍及使用(总结)
    蓝萝卜blu netty3升netty4
    tcp nio 远程主机强迫关闭了一个现有的连接
    java 竖线分割字符串的问题
    15个免费好用的抓包工具
    JSP 基础之 JSTL <c:forEach>用法
    JSP中多条件判断
    怎么不让控制台system.out.println()打印
  • 原文地址:https://www.cnblogs.com/zwl12549/p/1015980.html
Copyright © 2011-2022 走看看