root/as3/CrossDomainBridge/src/net/jirox/crossdomainbridge/CrossDomainBridge.as

リビジョン 104, 2.6 kB (コミッタ: jirox, コミット時期: 4 年 前)

時間を待たなくても実行できるように修正

Line 
1 /*
2  * Jiro Iwamoto. <jirokun@no spam@gmail.com>
3  * http://d.hatena.ne.jp/sukesam
4  * http://jirox.net/blog/
5  *
6  * The MIT License
7  * --------
8  * Copyright (c) 2007 Jiro Iwamoto.
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a copy
11  * of this software and associated documentation files (the "Software"), to deal
12  * in the Software without restriction, including without limitation the rights
13  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14  * copies of the Software, and to permit persons to whom the Software is
15  * furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included in
18  * all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26  * THE SOFTWARE.
27  */
28
29 package net.jirox.crossdomainbridge {
30         import flash.display.Sprite;
31         import flash.external.ExternalInterface;
32         import mx.rpc.http.HTTPService;
33         import mx.rpc.events.ResultEvent;
34         import mx.rpc.events.FaultEvent;
35
36         public class CrossDomainBridge extends Sprite {
37                 private var onSuccess:String;
38                 private var onFailure:String;
39
40                 public function CrossDomainBridge() {
41                         ExternalInterface.addCallback('request', request);
42                         ExternalInterface.addCallback('registerCallback', registerCallback);
43                         // SWFの用意ができたので、flashvarsに指定されたrequestCallbackを実行する
44                         ExternalInterface.call('CrossDomainBridge.' + loaderInfo.parameters['requestCallback'], null);
45                 }
46
47                 private function registerCallback(obj:Object):void {
48                         this.onSuccess = obj.onSuccess;
49                         this.onFailure = obj.onFailure;
50                 }
51
52                 private function request(url:String, params:Object):void {
53                         var service:HTTPService = new HTTPService();
54                         service.url = url;
55
56                         service.addEventListener(ResultEvent.RESULT, result);
57                         service.addEventListener(FaultEvent.FAULT, fault);
58                         service.send(params);
59                 }
60
61                 private function result(event:ResultEvent):void {
62                         ExternalInterface.call("CrossDomainBridge." + this.onSuccess, event.result);
63                 }
64
65                 private function fault(event:FaultEvent):void {
66                         ExternalInterface.call("CrossDomainBridge." + this.onFailure, event);
67                 }
68         }
69 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。