BloggerAds廣告

相關文章

2012年10月4日 星期四

load json crossdomain

Simply a note for loading json cross-domain

i use $.ajax() method for better event handling


client side js coding:
$.ajax({
 url:"http://another.domain.com",
 
 dataType: 'jsonp', //stand for "json-padding", it is jsonp, not json
 
 //its "jsonpCallback", not "jsonCallback". the callback method name from JSON, will explain below
 jsonpCallback: 'jsonCallback', 
 
 //set this to true to let the method know im loading data cross-domain
 crossDomain : true, 
 //success handler
 success: function(data) {
  console.log("dosomthing")
 },
 
 //error handler
 error: function() {
   console.log("error occured")
 }
});

the json response, wrap the JSON with a function with the name which declared in jsonpCallback above:
jsonCallback(
 {
  "user":"littleshell",
  "gender":"male"
 }
);

2012年3月7日 星期三

The 1009 error on Loader.load()

Just a note about 1009 error on Loader.load()
the situation is that the main.swf attempts to load child.swf

on Child class
package {

 import flash.events.Event;
 import flash.display.Sprite;

 public class Child extends Sprite {

  public function Child() {
   initChild();
  }
  
  public function initChild():void {
   stage.focus = this;
  }
 }
}
on Main class
package net.littleshell {
 import flash.display.Loader;
 import flash.display.Sprite;
 import flash.events.Event;
 import flash.net.URLRequest;
 
 public class Main extends Sprite {
  
  private var l:Loader
  
  public function Main() {
   init();
  }
  
  public function loadSWF($url:String):void {
   var rq:URLRequest = new URLRequest($url);
   l.load(rq);
  }
  
  private function init():void {
   initLoader();  
   loadSWF("child.swf");
  }
  
  private function initLoader():void {
   l = new Loader();
   l.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete);
   
   addChild(l);
  }
  
  private function loader_complete(e:Event):void {
   //blar blar blar
  }
 }
}
in such case, a #1009 error will be thrown in child.swf it is because child.swf references the stage object too soon.
to solve it, simply run your code when ADDED_TO_STAGE event was dispatched.

Modified Child class
package net.littleshell {

 import flash.events.Event;
 import flash.display.Sprite;

 public class Child extends Sprite {

  public function Child() {
   addEventListener(Event.ADDED_TO_STAGE, initChild);
   initChild();
  }
  
  public function initChild(e:Event == null):void {
   removeEventListener(Event.ADDED_TO_STAGE, initChild)
   
   //its now safe to do anything
   stage.focus = this;
  }
 }
}

2011年6月14日 星期二

A very convenience way to use google map

Since i pubilshed the article about facebook share last time, i got so many new visitors~
It is pleased to know that my knowledge helps

Also i've got quiet alot visitors from western, i decided using english this time

Just discovered a very convenience way to use google map.
its called Google static maps





<img src="http://maps.google.com/maps/api/staticmap?
center=North Point
&zoom=12
&size=512x512
&maptype=roadmap
&markers=color:Red|label:A|North Point
&sensor=false"
/>


for the sake of demonstration, i have not escape the html
you should escape it
as you see, it just use an img HTML tag
of cause~ you cannot have any interactions but this is much easier to use then JS version