Silverlight:Downloader的使用(Method篇)

方法:

(1)Aboat
取消downloader的请求和重设到他们初始状态.
downloaderObject.Abort()
Aboat的方法取消已经执行的Downloader对象的Send方法.还有,Abort方法重新设置Downloader属性到初试化状态.

Property name

Initial state

DownloadProgress (Downloader)

0

Status

0

StatusText

Empty string


(2)Equals
检测一个对象与当前对象是否相等.

返回值是Boolean,如果对象相同为true,否则为false;

Equals是引用用相等.在Silverlight1.0中,适用于两个实例相比较,如每一个Point初试化同样的值.另一方面,如果你创建两个Point实例X,Y并且值为0,0,用Equals方法他们将不相等.

一些对象类型被列表后应用于抽象类型,之前这个方法不能被真实调用JavaScript中的类型,因为有JavaScript程序中没有方法获得抽象类型的实例.

(3)GetHost
得到一个Silverlight plug-in引用包含调用对象.
retval = object.GetHost()

返回值类型为Object,Silverlight plug-in的引用实例包含指定对象.

GetHost方法能被使用在Silverlight object model的任何对象找到Silverlight plug-in实例包含这个对象,这个方法特别被用来通过放入到一个事件函数中找回Silverlight plug-in,sender参数通常是一个DependencyObject.

一些对象类型被列表后应用于抽象类型,之前这个方法不能被真实调用JavaScript中的类型,因为有JavaScript程序中没有方法获得抽象类型的实例.

事例:

下面是怎样通过KeyUp事件中找到a Silverlight plug-in object:
function  onKeyUp(sender, keyEventArgs)
{
    
// Determine whether the keystroke combination CTRL+V was detected.
    if ((keyEventArgs.key == 51&& (keyEventArgs.ctrl == true))
    
{
        
// Retrieve a reference to the plug-in.
        var plugin = sender.getHost();

        
// Determine whether the 1.0 version of Silverlight is available.
        alert("Silverlight 1.0: " + plugin.isVersionSupported("1.0"));
    }

}

在案例中需要使用HTML Document Object Model (DOM)访问Plug-in元素,如width,height,你能同过使用DOM查找的他们的ID值.下面就是一个怎样通过DOM查找Silverlight plug-in 实例,就是使用document.getElementById方法.

var  plugin_1  =  document.getElementById( " SLPlugin_1 " );

(4)GetResponseText

找回一个指定包的部分下载数据.
retval  =  downloaderObject.GetResponseText(part)

参数:
 参数名 类型 描述
 part
 String类型 指定下载一部分内容包的一部分.这个part不是一个可选参数, 你必须在至少指定空字符串或一个语法错误.

   

返回值类型为Object,下载数据,如在HTML中,返回值能被验证和传递一个字符串进入包中,但最终说明还是凡这个属性你就设置这个值.

Downloader对象求情完成,GetResponseText方法返回一个下载内容的描述的字符串.来于GetResponseText的返回值能呈现一个XAML,JavaScript,media,image.

如果你不能求情包的一部分,Downloader 请求只返回一个单独东西,你特别得到ResponseText属性比GetResponseText更好些.

(5)GetValue,SetValue
SetValue 设定指定属性的值(SetValue的概念与GetValue差不多)
GetValue 得到指定属性的值.
retval  =  object.GetValue(propertyName)


返回类型是Object

你能使用GetValue方法得到Silverlight属性的值,可是,你通常不需要这个方法得到属性值,因为所有Silverlight属性都支持JavaScript语言.
你能使用GetValue方法得到Silverlight属性的值如Canvas.Left.着个案例,追加属性名就是为所属类名追加属性,一个点,和追加属性名:value = object.GetValue("ownerType.propertyName").可是追加对象属性还支持这样形式value = object["ownerType.propertyName"].
事例:

详细的使用GetValue方法得到属性值:
function  onMouseLeftButtonUp(sender, index)
{
    
// Get the property value using the GetValue method.
    var opacity = sender.getValue("opacity");

    
// Get the property value using the equivalent "." notation.
    var opacity = sender.opacity;

    alert(
"Opacity = " + opacity);
}

(6)Open

初始化下载请求.

downloaderObject.Open(verb, uri)

参数:
  verb String类型 下载类型的行为,支持"Get".
  uri String类型 被下载的内容的URI.

Open方法初始化Downloader对象指定action执行和content执行.可是下载并没有被提交直到调用Send方法.

指定Open方法的uri必须与hosting HTML页面最初指定的uri一样.Cross-domain 下载Downloader APIs不能被许可.还(\)在Downloader URIs不能被许可,只能使用(/).通常,最优实践都是被使用来查找URIs,主要都是基于hosting HTML page的位置.

事例:

下面是使用Open 方法:

//  Event handler for initializing and executing a download request.
function  onMouseLeftButtonUp(sender, eventArgs)
{
    
// Retrieve a reference to the plug-in.
    var slPlugin = sender.getHost();

    
// Create a Downloader object.
    var downloader = slPlugin.createObject("downloader");

    
// Add DownloadProgressChanged and Completed events.
    downloader.addEventListener("downloadProgressChanged", onDownloadProgressChanged);
    downloader.addEventListener(
"completed", onCompleted);

    
// Initialize the Downloader request.
    // NOTE: downloader APIs disallow file:\\ scheme
    // you must run this sample over localhost: or off a server or the following call will fail

    downloader.open(
"GET""promo.png");

    
// Execute the Downloader request.
    downloader.send();
}

(7)Send
执行下载请求

downloaderObject.Send()

Send 方法执行请求下载数据.Send方法执行为异步.如果你需要知道精确的请求内容控制,你应该在调用Send方法之前追加Completed event.

企图一个cross-domain下载或尝试通过文件模式(FILE scheme)下载,失败将不能使用Completed or DownloadFailed events,并且Send方法调用将提示错误.

事例

下面是使用Send 方法.
//  Event handler for initializing and executing a download request.
function  onMouseLeftButtonUp(sender, eventArgs)
{
    
// Retrieve a reference to the plug-in.
    var slPlugin = sender.getHost();

    
// Create a Downloader object.
    var downloader = slPlugin.createObject("downloader");

    
// Add DownloadProgressChanged and Completed events.
    downloader.addEventListener("downloadProgressChanged", onDownloadProgressChanged);
    downloader.addEventListener(
"completed", onCompleted);

    
// Initialize the Downloader request.
    // NOTE: downloader APIs disallow file:\\ scheme
    // you must run this sample over localhost: or off a server or the following call will fail

    downloader.open(
"GET""promo.png");

    
// Execute the Downloader request.
    downloader.send();
}



转载于:https://www.cnblogs.com/worksguo/articles/1084187.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值