LURLLoader Class
The URLLoader class downloads data from a URL as text, binary data, or URL-encoded variables. When you download a text data, can not be run on the local environment.
Constructor
LURLLoader
()
public
Item Index
Methods
Properties
Events
Methods
addEventListener
-
type
-
listener
Registers an event listener object with an LEventDispatcher object so that the listener receives notification of an event. You can register event listeners on all nodes in the display list for a specific type of event, phase, and priority.
After you successfully register an event listener, you cannot change its priority through additional calls to addEventListener(). To change a listener's priority, you must first call removeListener(). Then you can register the listener again with the new priority level.
If you no longer need an event listener, remove it by calling removeEventListener(), or memory problems could result.
Parameters:
-
type
StringThe type of event.
-
listener
FunctionThe listener function that processes the event.
callParent
-
functionName
-
arguments
call the method of parent。
Parameters:
-
functionName
Stringfunction's name
-
arguments
ArrayFixed value : arguments
Example:
function funA(){
LExtends(this,LObject,[]);
}
funA.prototype.myName = function(){
return "AAA";
}
function funB(){
LExtends(this,funA,[]);
}
funB.prototype.myName = function(){
return "BBB";
}
function funC(){
LExtends(this,funA,[]);
}
funC.prototype.myName = function(){
return this.callParent("myName",arguments);
}
LInit(1000/50,"legend",800,150,main);
function main(){
LGlobal.setDebug(true);
var objB = new funB();
trace(objB.myName());//BBB
var objC = new funC();
trace(objC.myName());//AAA
}
dispatchEvent
-
event
Dispatches an event into the event flow. The event target is the LEventDispatcher object upon which the dispatchEvent() method is called.
Parameters:
-
event
LEvent | StringThe Event object that is dispatched into the event flow. If the event is being redispatched, a clone of the event is created automatically. After an event is dispatched, its target property cannot be changed, so you must create a new copy of the event for redispatching to work.
Returns:
A value of true if the event was successfully dispatched. function MyEventObject(){ var self = this; LExtends(self,LSprite,[]); self.graphics.drawRect(1,"#000000",[0,0,100,100],true,"#000000"); self.graphics.drawRect(1,"#FF0000",[100,0,100,100],true,"#FF0000"); self.addEventListener(LMouseEvent.MOUSE_UP,self.onclick); self.addEventListener(MyEventObject.CLICK_LEFT,function(event){ trace("dispatchEvent"); }); self.addEventListener(MyEventObject.CLICK_RIGHT,function(event){ trace("dispatchEvent event.name = " + event.name); }); } MyEventObject.CLICK_LEFT = "click_left"; MyEventObject.CLICK_RIGHT = "click_right"; MyEventObject.prototype.onclick = function(event){ var self = event.clickTarget; if(event.selfX < 100){ self.dispatchEvent(MyEventObject.CLICK_LEFT); }else{ var event = new LEvent(MyEventObject.CLICK_RIGHT); event.name = "LEvent Test"; self.dispatchEvent(event); } }
hasEventListener
-
type
Checks whether the LEventDispatcher object has any listeners registered for a specific type of event. This allows you to determine where an LEventDispatcher object has altered handling of an event type in the event flow hierarchy.
Parameters:
-
type
StringThe type of event.
Returns:
A value of true if a listener of the specified type is registered; false otherwise.
load
-
url
-
type
Sends and loads data from the specified URL.
Parameters:
-
url
StringThe URL to be requested.
-
type
Stringfile type,Currently supports "text","js".
Example:
LInit(1000/50,"legend",800,450,main);
var loader;
function main(){
LGlobal.setDebug(true);
loader = new LURLLoader();
loader.addEventListener(LEvent.COMPLETE, loadTxt);
loader.load("test.txt", "text");
}
function loadTxt (event) {
trace(loader.objectIndex == event.currentTarget.objectIndex);//true
trace(event.currentTarget.data == event.target);//true
trace("event.target = " + event.target);
}
removeAllEventListener
()
public
Removes all the listeners from the LEventDispatcher object.
removeEventListener
-
type
-
listener
Removes a listener from the LEventDispatcher object. If there is no matching listener registered with the LEventDispatcher object, a call to this method has no effect.
Parameters:
-
type
StringThe type of event.
-
listener
FunctionThe listener object to remove.
Properties
objectIndex
Int
public
ID of the object
Events
LEvent.COMPLETE
when the text file or js file is loaded.