annie.URLLoader Class
小游戏不支持 小程序不支持
资源加载类,后台请求,加载资源和后台交互都可以使用此类Methods
Properties
Methods
addEventListener
addEventListener
(
-
type
-
listener
-
useCapture
)
Void
public
给对象添加一个侦听
Parameters:
name | type | flag | description |
---|---|---|---|
type
| String | 侦听类型 | |
listener
| Function | 侦听后的回调方法,如果这个方法是类实例的方法,为了this引用的正确性,请在方法参数后加上.bind(this); | |
useCapture
| Boolean | true 捕获阶段 false 冒泡阶段 默认 true |
Returns:
Example:
this.addEventListener(annie.Event.ADD_TO_STAGE,function(e){console.log(this);}.bind(this));
addHeader
addHeader
(
-
name
-
value
)
添加自定义头
Parameters:
name | type | flag | description |
---|---|---|---|
name
| Object | ||
value
| Object |
destroy
destroy
()
Void
public
销毁一个对象 销毁之前一定要做完其他善后工作,否则有可能会出错 特别注意不能在对象自身方法或事件里调用此方法。 比如,不要在显示对象自身的 annie.Event.ON_REMOVE_TO_STAGE 或者其他类似事件调用,一定会报错
Returns:
dispatchEvent
dispatchEvent
(
-
event
-
data
-
useCapture
)
Boolean
public
广播侦听
Parameters:
name | type | flag | description |
---|---|---|---|
event
| annie.Event | String | 广播所带的事件对象,如果传的是字符串则自动生成一个annie.Event对象,事件类型就是传入进来的字符串的值 | |
data
| Object | 广播后跟着事件一起传过去的其他任信息,默认值为null | |
useCapture
| Boolean | true 捕获阶段 false 冒泡阶段 默认 true |
Returns:
如果有收听者则返回true
Example:
var mySprite=new annie.Sprite(),
yourEvent=new annie.Event("yourCustomerEvent");
yourEvent.data={a:1,b:2,c:"hello",d:{aa:1,bb:2}};
mySprite.addEventListener("yourCustomerEvent",function(e){
console.log(e.data);
})
mySprite.dispatchEvent(yourEvent);
hasEventListener
hasEventListener
(
-
type
-
useCapture
)
Boolean
public
是否有添加过此类型的侦听
Parameters:
name | type | flag | description |
---|---|---|---|
type
| String | 侦听类型 | |
useCapture
| Boolean | true 捕获阶段 false 冒泡阶段 默认 true |
Returns:
如果有则返回true
load
load
(
-
url
-
contentType
)
public
加载或请求数据
Parameters:
name | type | flag | description |
---|---|---|---|
url
| String | ||
contentType
| String | 如果请求类型需要设置主体类型,有form json binary jsonp等,请设置 默认为form |
loadCancel
loadCancel
()
public
取消加载
removeAllEventListener
removeAllEventListener
()
Void
public
移除对象中所有的侦听
Returns:
removeEventListener
removeEventListener
(
-
type
-
listener
-
useCapture
)
Void
public
移除对应类型的侦听
Parameters:
name | type | flag | description |
---|---|---|---|
type
| String | 要移除的侦听类型 | |
listener
| Function | 侦听时绑定的回调方法 | |
useCapture
| Boolean | true 捕获阶段 false 冒泡阶段 默认 true |
Returns:
URLLoader
URLLoader
(
-
type
)
构造函数
Parameters:
name | type | flag | description |
---|---|---|---|
type
| Object | text json js xml image sound css svg video unKnow |
Properties
data
Object
public
需要向后台传送的数据对象
Default:
null
instanceId
Number
public
每一个annie引擎对象都会有一个唯一的id码。
Example:
//获取 annie引擎类对象唯一码
console.log(this.instanceId);
instanceType
String
public
每一个annie类都有一个实例类型字符串,通过这个字符串,你能知道这个实例是从哪个类实例而来
method
String
public
请求后台的类型 get post
Default:
get
responseType
String
public
后台返回来的数据类型
Default:
null
url
String
public
请求的url地址
Events
annie.Event.ABORT
annie.URLLoader中断事件
annie.Event.COMPLETE
完成事件
annie.Event.ERROR
annie.URLLoader出错事件
annie.Event.PROGRESS
annie.URLLoader加载过程事件
annie.Event.START
annie.URLLoader开始事件