Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.yahoo.yui
- {
- import flash.accessibility.*;
- import flash.display.*;
- import flash.errors.*;
- import flash.events.*;
- import flash.external.*;
- import flash.system.*;
- import flash.text.*;
- public class YUIAdapter extends Sprite
- {
- protected var elementID:String;
- protected var javaScriptEventHandler:String;
- private var _component:DisplayObject;
- private var _errorText:TextField;
- private var _altText:String;
- public function YUIAdapter()
- {
- var swfReady:Object;
- if (this.stage)
- {
- this.stage.addEventListener(Event.RESIZE, this.stageResizeHandler);
- this.stage.scaleMode = StageScaleMode.NO_SCALE;
- this.stage.align = StageAlign.TOP_LEFT;
- }
- try
- {
- ExternalInterface.marshallExceptions = true;
- }
- catch (error:Error)
- {
- }
- this._errorText = new TextField();
- this._errorText.defaultTextFormat = new TextFormat("_sans", 10, 16711680);
- this._errorText.wordWrap = true;
- this._errorText.autoSize = TextFieldAutoSize.LEFT;
- this._errorText.selectable = false;
- this._errorText.mouseEnabled = false;
- this.addChild(this._errorText);
- this.addEventListener(Event.ADDED, this.addedHandler);
- if (ExternalInterface.available)
- {
- this.initializeComponent();
- swfReady;
- this.dispatchEventToJavaScript(swfReady);
- }
- else
- {
- throw new IOError("Flash YUIComponent cannot communicate with JavaScript content.");
- }
- return;
- }// end function
- protected function get component() : DisplayObject
- {
- return this._component;
- }// end function
- protected function set component(param1:DisplayObject) : void
- {
- this._component = param1;
- this.refreshComponentSize();
- return;
- }// end function
- public function getAltText() : String
- {
- return this._altText;
- }// end function
- public function setAltText(param1:String) : void
- {
- this._altText = param1;
- var _loc_2:* = new AccessibilityProperties();
- _loc_2.name = this._altText;
- _loc_2.forceSimple = true;
- _loc_2.noAutoLabeling = true;
- this.component.accessibilityProperties = _loc_2;
- return;
- }// end function
- protected function initializeComponent() : void
- {
- this.elementID = this.loaderInfo.parameters.YUISwfId;
- this.javaScriptEventHandler = this.loaderInfo.parameters.YUIBridgeCallback;
- var jsCheck:* = /^[A-Za-z0-9.]*$/g;
- if (!jsCheck.test(this.javaScriptEventHandler))
- {
- this.javaScriptEventHandler = "";
- }
- var allowedDomain:* = this.loaderInfo.parameters.allowedDomain;
- if (allowedDomain)
- {
- Security.allowDomain(allowedDomain);
- this.log("allowing: " + allowedDomain);
- }
- try
- {
- ExternalInterface.addCallback("getAltText", this.getAltText);
- ExternalInterface.addCallback("setAltText", this.setAltText);
- }
- catch (error:SecurityError)
- {
- }
- return;
- }// end function
- protected function log(param1:Object, param2:String = null) : void
- {
- if (param1 == null)
- {
- param1 = "";
- }
- this.dispatchEventToJavaScript({type:"log", message:param1.toString(), category:param2});
- return;
- }// end function
- protected function showFatalError(param1:Object) : void
- {
- if (!param1)
- {
- param1 = "";
- }
- if (this._errorText)
- {
- this._errorText.appendText(param1.toString());
- this._errorText.scrollV = this._errorText.maxScrollV;
- this._errorText.mouseEnabled = true;
- this._errorText.selectable = true;
- }
- return;
- }// end function
- protected function dispatchEventToJavaScript(param1:Object) : void
- {
- var event:* = param1;
- try
- {
- if (ExternalInterface.available)
- {
- ExternalInterface.call(this.javaScriptEventHandler, this.elementID, event);
- }
- }
- catch (error:Error)
- {
- if (error is SecurityError)
- {
- this.showFatalError("Warning: Cannot establish communication between YUI Charts and JavaScript. YUI Charts must be served from HTTP and cannot be viewed locally with file:/// protocol unless location is trusted by Flash Player.\n\nFor more information see:\nhttp://www.adobe.com/products/flashplayer/articles/localcontent/\n\n");
- }
- }
- return;
- }// end function
- protected function stageResizeHandler(event:Event) : void
- {
- this.refreshComponentSize();
- if (this._errorText)
- {
- this._errorText.width = this.stage.stageWidth;
- this._errorText.height = this.stage.stageHeight;
- }
- this.log("resize (width: " + this.stage.stageWidth + ", height: " + this.stage.stageHeight + ")", LoggerCategory.INFO);
- return;
- }// end function
- protected function refreshComponentSize() : void
- {
- if (this.component)
- {
- var _loc_1:* = 0;
- this.component.y = 0;
- this.component.x = _loc_1;
- this.component.width = this.stage.stageWidth;
- this.component.height = this.stage.stageHeight;
- }
- return;
- }// end function
- protected function addedHandler(event:Event) : void
- {
- this.setChildIndex(this._errorText, (this.numChildren - 1));
- return;
- }// end function
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement