/**
* 四捨五入格式化數字小數精度,預設整數,使用千分位
* @param number Number 要格式化的數字
* @param decimalCount int 小數的個數,預設0
* @param useThousandsSeparator Boolean 是否使用千分位, 預設true
* @return 格式化後的字串
*/
public static function formatNumberDecimal(number:Number, decimalCount:int = 2, useThousandsSeparator:Boolean = true):String {
var numberFormatter:NumberFormatter = new NumberFormatter("en-US");
//小數分隔符號
numberFormatter.decimalSeparator = ".";
//小數點後的位數
numberFormatter.fractionalDigits = decimalCount;
//是否自動在小數後補位
numberFormatter.trailingZeros = false;
//當小數左側沒有整數時,加上前導0,例如:0.1
numberFormatter.leadingZero = true;
//3;* 123,456,789.12
//3;2;* 12,34,56,789.12
//3 123456,789.12
//分組表達式,採用3位一組的千分法
numberFormatter.groupingPattern = "3;*";
//千分位的分組
numberFormatter.useGrouping = useThousandsSeparator;
//千分位的分隔符
numberFormatter.groupingSeparator = ",";
//返回格式化後的字串
return numberFormatter.formatNumber(number);
}
搜尋部落格文章
2013年3月5日 星期二
NumberFormatter 地區貨幣格式化
2013年3月4日 星期一
[轉] AS3複製顯示物件
一,複製舞台上的影片剪
方法1——反射方法:
var ClassRef:Class = getDefinitionByName(getQualifiedClassName(t_mc)) as Class;
var clone_mc:DisplayObject = new ClassRef();
addChild(clone_mc);
方法2——構造器方法:
var ClassRef:Class = t_mc.constructor;
var clone_mc:MovieClip = new ClassRef();
addChild(clone_mc);
方法3——編譯器自動生成類方法:
此方法是方法1的變種,它比方法1更加簡單、粗暴、有效。下面我將為大家特別講解一下這個方法:
首先,在庫中創建一個影片剪輯,隨意繪製一個圖形,然後在第一幀上加上一個單行註釋符“//”;
接下來,將剛才創建的影片剪輯拖到舞台上,創建一個示例,命名為“t_mc”;
現在,重點來了,我們在主時間線上寫下如下所示語句,然後按下Ctrl+Enter,仔細觀察一下輸出面板中輸出的信息。
trace(getQualifiedClassName(t_mc));
你發現,輸出結果是“_fla::Timeline_1 ”。出於對函數getQualifiedClassName的作用的清晰理解,你立刻就想到,這個Timeline_1應該就是編譯器自動為我們的庫中的影片剪輯創建的類。我們貌似可以用這個類new出多個一樣的影片剪輯來哦!是不是這樣呢?我們來驗證一下:
var clone_mc:DisplayObject = new Timeline_1();
addChild(clone_mc);
Ctrl+Enter,你驚喜的發現,我們成功了!實驗到這裡,可能很多朋友已經興奮地準備去寫學習總結了。兄弟們,不要急,我們的實驗還沒完——現在,我們用同樣的方法,再次在庫中創建一個影片剪輯。然後也將它拖到舞台上創建一個實例,取名為“d_mc”。接下來,我們將trace(getQualifiedClassName(t_mc)); 語句中的“t_mc”改成“d_mc”。測試一下影片,這次輸出的結果竟然是“flash.display::MovieClip”。
忽忽!傻了吧,不能用new MovieClip來複製“d_mc”了吧!
咋解決這個問題呢?我給大家一點點提示:試試將庫中那兩個影片剪輯各取一個響亮的名字(名稱),然後再看一下輸出的類名是什麼。
使用以上方法複製影片剪輯時需要注意:
必須在庫中創建影片剪輯,並將庫中的影片剪輯拖到舞台上創建了一個實例;
影片剪輯的幀上必須包含代碼(註釋也行,最簡單的就是加一個單行註釋符號“//”);
二,複製Loader加載的swf
複製外部加載的swf是一個相對高級的操作,步驟比較多,過程相對複雜,要闡述清楚原理細節需要很大篇幅的文字,因此,這裡我就偷懶不詳細寫說明了,純用代碼來說明問題,希望對看得懂的朋友起到拋磚引玉的作用。
方法1——ByteArray深度複製
var byteLoader:URLLoader = new URLLoader();
byteLoader.dataFormat = URLLoaderDataFormat.BINARY;
byteLoader.addEventListener(Event.COMPLETE, loadCompleteHandler);
var loader:Loader = new Loader();
loader.y = 200;
addChild(loader);
loader.contentLoaderInfo.addEventListener(Event.INIT, loadInitHandler);
function loadInitHandler(evt:Event):void
{
var cloneLoder:Loader = new Loader();
addChild(cloneLoder);
cloneLoder.loadBytes(byteLoader.data);
}
byteLoader.load(new URLRequest("t.swf"));
function loadCompleteHandler(evt:Event):void
{
loader.loadBytes(byteLoader.data);
}
簡單原理:用URLLoader將外部的swf以二進制數據格式加載到ByteArray中,然後用Loader類的loadBytes去加載URLLoader中的ByteArray。
方法2——ApplicationDomain 運行時動態類複製
var loader:Loader = new Loader();
loader.y = 200;
addChild(loader);
loader.contentLoaderInfo.addEventListener(Event.INIT, loadInitHandler);
var context:LoaderContext = new LoaderContext();
context.applicationDomain=ApplicationDomain.currentDomain;
loader.load(new URLRequest("t.swf"), context);
function loadInitHandler(evt:Event):void
{
var ClassRef:Class = loader.contentLoaderInfo.applicationDomain.getDefinition("TestClass") as Class;
var clone_mc: MovieClip = new ClassRef();
addChild(clone_mc);
}
注意:
1.以上兩種複制方法,由於都需要加載swf文件,因此需要文件級別的本地安全性;
2.使用第二種方法(ApplicationDomain)時,生成“t.swf”時必須為舞台添加文檔類屬性。添加的文檔類可以是具體的外部as類,也可以僅僅是一個名字。上例中我添加的文檔名為”TestClass”, getDefinition("TestClass")中填的參數內容應該跟要復制的swf的文檔類名相同。
3. ApplicationDomain還有更多高級用法,有興趣的高級AS程序員可以去研究一下。
出處:http://hi.baidu.com/javabbs/blog/item/dcb9a1456269182dcefca32d.html
方法1——反射方法:
var ClassRef:Class = getDefinitionByName(getQualifiedClassName(t_mc)) as Class;
var clone_mc:DisplayObject = new ClassRef();
addChild(clone_mc);
方法2——構造器方法:
var ClassRef:Class = t_mc.constructor;
var clone_mc:MovieClip = new ClassRef();
addChild(clone_mc);
方法3——編譯器自動生成類方法:
此方法是方法1的變種,它比方法1更加簡單、粗暴、有效。下面我將為大家特別講解一下這個方法:
首先,在庫中創建一個影片剪輯,隨意繪製一個圖形,然後在第一幀上加上一個單行註釋符“//”;
接下來,將剛才創建的影片剪輯拖到舞台上,創建一個示例,命名為“t_mc”;
現在,重點來了,我們在主時間線上寫下如下所示語句,然後按下Ctrl+Enter,仔細觀察一下輸出面板中輸出的信息。
trace(getQualifiedClassName(t_mc));
你發現,輸出結果是“_fla::Timeline_1 ”。出於對函數getQualifiedClassName的作用的清晰理解,你立刻就想到,這個Timeline_1應該就是編譯器自動為我們的庫中的影片剪輯創建的類。我們貌似可以用這個類new出多個一樣的影片剪輯來哦!是不是這樣呢?我們來驗證一下:
var clone_mc:DisplayObject = new Timeline_1();
addChild(clone_mc);
Ctrl+Enter,你驚喜的發現,我們成功了!實驗到這裡,可能很多朋友已經興奮地準備去寫學習總結了。兄弟們,不要急,我們的實驗還沒完——現在,我們用同樣的方法,再次在庫中創建一個影片剪輯。然後也將它拖到舞台上創建一個實例,取名為“d_mc”。接下來,我們將trace(getQualifiedClassName(t_mc)); 語句中的“t_mc”改成“d_mc”。測試一下影片,這次輸出的結果竟然是“flash.display::MovieClip”。
忽忽!傻了吧,不能用new MovieClip來複製“d_mc”了吧!
咋解決這個問題呢?我給大家一點點提示:試試將庫中那兩個影片剪輯各取一個響亮的名字(名稱),然後再看一下輸出的類名是什麼。
使用以上方法複製影片剪輯時需要注意:
必須在庫中創建影片剪輯,並將庫中的影片剪輯拖到舞台上創建了一個實例;
影片剪輯的幀上必須包含代碼(註釋也行,最簡單的就是加一個單行註釋符號“//”);
二,複製Loader加載的swf
複製外部加載的swf是一個相對高級的操作,步驟比較多,過程相對複雜,要闡述清楚原理細節需要很大篇幅的文字,因此,這裡我就偷懶不詳細寫說明了,純用代碼來說明問題,希望對看得懂的朋友起到拋磚引玉的作用。
方法1——ByteArray深度複製
var byteLoader:URLLoader = new URLLoader();
byteLoader.dataFormat = URLLoaderDataFormat.BINARY;
byteLoader.addEventListener(Event.COMPLETE, loadCompleteHandler);
var loader:Loader = new Loader();
loader.y = 200;
addChild(loader);
loader.contentLoaderInfo.addEventListener(Event.INIT, loadInitHandler);
function loadInitHandler(evt:Event):void
{
var cloneLoder:Loader = new Loader();
addChild(cloneLoder);
cloneLoder.loadBytes(byteLoader.data);
}
byteLoader.load(new URLRequest("t.swf"));
function loadCompleteHandler(evt:Event):void
{
loader.loadBytes(byteLoader.data);
}
簡單原理:用URLLoader將外部的swf以二進制數據格式加載到ByteArray中,然後用Loader類的loadBytes去加載URLLoader中的ByteArray。
方法2——ApplicationDomain 運行時動態類複製
var loader:Loader = new Loader();
loader.y = 200;
addChild(loader);
loader.contentLoaderInfo.addEventListener(Event.INIT, loadInitHandler);
var context:LoaderContext = new LoaderContext();
context.applicationDomain=ApplicationDomain.currentDomain;
loader.load(new URLRequest("t.swf"), context);
function loadInitHandler(evt:Event):void
{
var ClassRef:Class = loader.contentLoaderInfo.applicationDomain.getDefinition("TestClass") as Class;
var clone_mc: MovieClip = new ClassRef();
addChild(clone_mc);
}
注意:
1.以上兩種複制方法,由於都需要加載swf文件,因此需要文件級別的本地安全性;
2.使用第二種方法(ApplicationDomain)時,生成“t.swf”時必須為舞台添加文檔類屬性。添加的文檔類可以是具體的外部as類,也可以僅僅是一個名字。上例中我添加的文檔名為”TestClass”, getDefinition("TestClass")中填的參數內容應該跟要復制的swf的文檔類名相同。
3. ApplicationDomain還有更多高級用法,有興趣的高級AS程序員可以去研究一下。
出處:http://hi.baidu.com/javabbs/blog/item/dcb9a1456269182dcefca32d.html
2013年2月5日 星期二
[轉] 圖片安全性操作解決方法
AS3 - Load a Remote Image from Any URL / Domain with No Stupid Security Sandbox Errors
Friday, September 18, 2009 by Sean PIssue:
You want to load an image from an unkown external URL. It works on your computer... Sandbox Security error online (and/or the annoying images just showing up as solid white feature).
By default, Flash wants a crossdomain.xml file on the server you are loading from, but let's say there is none, because it's probably not your website. Well, then the flash player isn't going to let you take that data and do what you want with it.
Attempting to do so will give you some error similar to:
*** Security Sandbox Violation ***
SecurityDomain 'http://www.designercolin.com/temp/ispire/get_boards.php' tried to access incompatible context 'somewebsite.com/someImage_here.jpg'
SecurityDomain 'http://www.designercolin.com/temp/ispire/get_boards.php' tried to access incompatible context 'somewebsite.com/someImage_here.jpg'
Half-Solution (aka the adobe way):
According to adobe's docs you need to do a couple things to work around this (to not access this remote data directly)- bypass policy file, and don't manipulate it in any way (ahem-lame). See the next solution if you need to access or smooth the bitmap data.
1) Use a LoaderContext instance with checkPolicyFile=false - this will tell it not to worry about the cross-domain issue and use the loader context object as 2nd parameter in Loader.load() call
var lc:LoaderContext = new LoaderContext();
lc.checkPolicyFile = false; // bypass security sandbox / policy file - does this effect quality when scaling?
_myLoader = new Loader();
_myLoader.contentLoaderInfo.addEventListener(Event.INIT, onImageLoaded);
// load new url
_myURLRequest = new URLRequest($url);
_myLoader.load(_myURLRequest, lc);
lc.checkPolicyFile = false; // bypass security sandbox / policy file - does this effect quality when scaling?
_myLoader = new Loader();
_myLoader.contentLoaderInfo.addEventListener(Event.INIT, onImageLoaded);
// load new url
_myURLRequest = new URLRequest($url);
_myLoader.load(_myURLRequest, lc);
2) Show the loaded image - This is where you may get the error (this is what had me pulling my hair out)
Even with the checkPolicyFile = false set, I had to add the loader to a SPRITE (not movieclip, and not the loader content!), as this would be accessing data outside the sandbox
private function onImageLoaded($e:Event):void
{
_innerImage = this.addChild(new Sprite());
//_innerImage.addChild($e.currentTarget.content); // doesn't work. sandbox security error
_innerImage.addChild(_myLoader);
}
{
_innerImage = this.addChild(new Sprite());
//_innerImage.addChild($e.currentTarget.content); // doesn't work. sandbox security error
_innerImage.addChild(_myLoader);
}
...by doing this, you will not have accessed this image data in any way to get the error, so you can load the image data but if you need to access the bitmapdata directly (or create a movie clip apparently?), I don't think it will work.
I'm not sure exactly why adding to a Sprite() instead of MovieClip() allowed it to work for me, they both are DisplayObjects, maybe there is something in the MovieClip constructor that accesses the image data... Whatever, it's stupid that you have to do that in the first place, so why would the method make sense! See the other / better solution below..
Quality Question- for remote image data without policy file:
What I really want to know is (for printing purposes) - using this method, since there is no access directly to the image data, when you scale the image... does it not render with smoothing / anti-aliasing? Is it poor quality outside of native dimensions? Or is it basically the same quality as scaling a local image within security domain? Final conclusion is that it's better to use a proxy if the image has to be anything but native (original size/scale)...
Better Solution- Go Around It
Well, since flash is finicky and now has had different bugs with different flash player versions, the smart thing to do is cut your losses and just go around this issue. A local .php file or similar service as a proxy to cross-domains URLs will do the trick and retrieve the images and flash will basically think they were hosted locally.
Then, in flash you should set up a class that will prefix URLs for you, maybe extend the URLLoader...
However you do it, you want to prefix remote URLs with your proxy URL, and pass along the intended URL something like:
http://www.YourFlashSite.com/proxy/getimage.php?url=http://someOtherWebsite.com/someImage.jpg
On creating the PHP proxy to retrieve the file.. theres a few you can find with google but i have had issues with the majority of them-
One common proxy issue with Flash is that if your progressEvent.bytesTotal is 0 (making your preloader show Infinity) it may be because your server has gzip enabled. You can use an app like Charles to see what your http activity looks like and see if there is gzip compression on the responses... turn off gzip for your proxy file and you're golden.
2013年1月22日 星期二
廣告Banner需要的參數clickTAG
Actionscript 2.0 (AS2)
On the top level Button or MovieClip apply following actionscript:on (release) {
getURL(_root.clickTAG, '_blank');
}
Or you can also do it by MovieClip or Button instance name:click_btn_name.onRelease = function(){
getURL(_root.clickTAG, '_blank');
}
方法一:
Actionscript 3.0 (AS3)
Give the Button some instance name for example click_btn and add following actionscript:import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
click_btn.addEventListener(MouseEvent.MOUSE_UP, onClick);
function onClick(e:MouseEvent):void {
var click_url:String = root.loaderInfo.parameters.clickTAG;
if(click_url) {
navigateToURL(new URLRequest(click_url), '_blank');
}
}
方法二:
// ONLY NEED FUNCTION LISTED ONCE!!!
function getClickTag():String{
for (var key:String in root.loaderInfo.parameters)
if(key.toLowerCase()=="clicktag")
return root.loaderInfo.parameters[key];
return "";
}
// END FUNCTION
// NEED THIS FOR EACH BUTTON - NOTE TO CHANGE THE "clicker_mc" to MATCH YOUR INSTANCE NAME
clicker_mc.addEventListener(MouseEvent.CLICK,function():void {
navigateToURL(new URLRequest(getClickTag()),"_blank");
});
2012年12月24日 星期一
[轉]Flash AS3.0學習筆記安全沙箱安全策略文件詳解Security類Application類使用詳解
使用 Flash Cs4中的安全沙箱詳解
掌握安全模型
安全模型從as2開始一直都是學習上的攔路虎,as3安全模型比起as2更加複雜。 凡是包括加載與通信的行為,如swf文件之間的通信,swf與網頁之間的通信,XMLSocket或webService等都受到安全機制的限制。 在幫助文件中隨時會提醒你注意安全模型,並且稱作焦點問題,最大的問題是當發布運行程序時時不時跳出一個安全對話框,讓初學者不知所措。 安全性問題確實很煩人,adobe也不願意搞的複雜,但是沒辦法,因為——人心太壞了,總是有些人要幹壞事,不得不建立法律來限制這些人。 經過整理,我盡量按照能夠接受的方式按順序講解,能讓看完教程的人不再為安全問題迷惑和煩惱的是寫這教程的目標。
本地和遠程:
1.本地和遠程文件:
本機上的swf文件和在本地網頁中嵌入的本地swf是本地文件,服務器上的swf或者服務器頁面嵌入的swf文件是遠程文件。
2.本地和遠程訪問:
使用file協議或路徑名訪問是本地訪問,通過http協議或其它協議訪問是網絡訪問。
關於中文路徑:最好保證路徑為英文名稱。 flash把路徑名統一使用網絡編碼,由於操作系統編碼環境的區別可能導致中文路徑有出現問題。 即使在同一個文件夾下,也可能因為文件夾名稱為中文載不進來。 因為as3可能會把相對路徑轉化為絕對路徑。
安全沙箱:
as3中共有4種沙箱類型:
Security.REMOTE:
遠程文件被放入這個沙箱中。 Security.REMOTE不能訪問訪問本地數據。 遠程之間遵守跨域安全策略。 頁面或容器有能力與flash控件通信。
Security.LOCAL_WITH_FILE:
可以訪問本地數據但不能以任何形式訪問網絡,包括:不能用url鏈接,不能載入遠程數據。 flash控件不能跟頁面或容器通信。 本地數據不能以任何方式發送到網絡。
Security.LOCAL_WITH_NETWORK:
允許本地文件訪問網絡。 訪問網絡要遵守跨域機制。 不能以任何方式訪問本地內容。
Security.LOCAL_TRUSTED:
既可以訪問本地內容又可以訪問網絡。 前提是被加入信任位置。 調式模式和生成的exe也是這個級別。 因為調試和運行exe都是用戶主動的行為,被看作用戶認可的。
除此之外:
遠程沙箱中的文件始終不能訪問本地。
位於相同沙箱中的資源才能互相訪問。
繞過沙箱:
若想繞過flash安全機制進行數據交換。 只有尋求第三方――服務器腳本。 通過服務器腳本互相交換數據。 但這樣也要遵守腳本之間的安全機制,而且不能進行文件交流。
SecurityDomain類
SecurityDomain類基於Object,使用import flash.system.SecurityDomain聲明。 SecurityDomain類是單例模式。 只能使用靜態屬性表示當前安全沙箱。 當swf跨域通信時,可以把跨域沙箱中的swf載入到本地安全沙箱中。
屬性:
SecurityDomain.currentDomain:SecurityDomain:
當前安全域
跨域訪問機制:
在服務器上,同一個域中的文件、數據或者swf可以任意訪問。 若要跨域訪問需被授權。 注意不同域名即使映射到相同IP地址也會被看成兩個域。 IP地址名和通過解析的地址也被看作兩個域。 有兩種授權方式:策略文件和作者授權。
策略文件:
策略文件聲明某個域中的文件可以被指定域訪問。 策略適用於所有形式的訪問。 是個xml文件,格式如:
策略文件中可以使用通配符。 使用*通配符表示能被所有網站訪問。 secure用於https協議與http互相訪問。 false表示允許互相訪問。
默認策略文件:
默認策略文件放在網站根目錄下面名字必須為crossdomain.xml。
加載策略文件:
若覺得默認策略文件給服務器維護造成影響。 可放到子域中,用System.security.loadPolicyFile(url)來加載。
策略文件類型:
策略文件分為頁面策略文件和套接字策略文件。 套接字策略文件需要指定端口,如:
由於flashPlayer只檢測套接字策略文件相同端口上的策略文件,而策略文件一般放入服務器中採用http訪問,這時只能使用默認策略文件並且使用Security.loadPolicyFile來加載,如:
Security.loadPolicyFile("http://socketServerHost.com/crossdomain.xml")
作者授權:
有時候只想開放某個swf文件而不是整個域中的數據,作者可以使用Security.allowDomain( )在swf中授權。 作者授權但並不代表互相通信。 除非互相授權。
Security類
Security類基於Object,使用import flash.system.Security聲明,Security類是個靜態類,用於處理安全訪問。
屬性:
Security.sandboxType:String
安全沙箱類型。 使用它的靜態常量表示。 對應上述的4中沙箱類型:
Security.REMOTE,
Security.LOCAL_WITH_FILE,
Security.LOCAL_WITH_NETWORK,
Security.LOCAL_TRUSTED
Security.exactSettings:Boolean
是否精確匹配域,默認為true。 精確匹配指不忽略域名中的機器名,如www.flash.com與john.flash.com被看作不同的域。
方法:
Security.allowDomain(…domains):void
在swf中允許指定域訪問。 多個參數表示多個域,如Security.allowDomain("www.adobe.com","www.macromedia.com","www.flash.com");
Security.allowInsecureDomain(…domains):void
允許https協議的域訪問。
Security.loadPolicyFile(url:String):void
加載策略文件。 當不使用默認策略文件時需要加載。
Security.showSettings(panel:String = "default"):void
顯示安全設置面板。
應用程序域:
允許跨域加載swf後,還可能出現加載的swf中的類與主類相同而產生衝突。 為此安全模型把加載的swf類用應用程序域劃分。 安全域為樹形結構。 加載的應用程序域可以是文檔類應用程序域的子域。 文檔類的父級安全域為系統安全域。 系統安全域包含所有flashPlayer類。 為了為我們提供靈活的訪問性,as3允許指定載入swf的位置是任何應用程序域。 加入子集應用程序域的文件能夠直接訪問父級應用程序域。 但父級必須使用getDefinition方法訪問子集應用程序域。 加入到文檔類應用程序域的文件父級和子集可以直接訪問但可能會產生同名衝突。 加載到系統應用程序域則被自動劃分,必須都使用getDefinition方法互相訪問。
ApplicationDomain類
ApplicationDomain基於Object類,使用import flash.system.Application聲明。 表示應用程序域。
屬性:
currentDomain:ApplicationDomain
當前應用程序域。
parentDomain:ApplicationDomain
父級應用程序域。
方法:
getDefinition(name:String):Object
從通過名稱從應用程序域中獲取類,命名空間或函數。
hasDefinition(name:String):Object
指定名稱的定義在應用程序域中是否存在。
設置權限必要時,我們想使用Security.LOCAL_TRUSTED沙箱進行本地數據和遠程進行通信。 可以更改本機flashPlayer配置文件或添加信任位置達到目的。 比如使用安裝程序在信任位置添加文件。 但是操作必須被授權。 as3的權限層次如圖:
管理員和用戶設置本地權限:
管理員設置:
系統管理員可以修改mms.cfg配置文件和設置全局flash player信任目錄。 mms.cfg為flashPlayer啟動時的安全信息配置文件,可以限制數據加載,隱私控制,播放器更新,本地文件安全性,全屏模式,舊版文件支持6大功能。 但最好不要動這個文件,因為影響太大了。 全局信任目錄中的地址能夠使所有用戶使用Security.LOCAL_TRUSTED沙箱。 全局信任目錄以及mms.cfg路徑在C:\windows\system32\Macromed\Flash\FlashPlayerTrust下。
用戶設置:
用戶也有自己的配置文件和信任目錄。 在
C:\Documents and Settings\xin\Application Data\Macromedia\
Flash Player\#Security\FlashPlayerTrust下。 用戶也可以直接使用設置管理器來代替修改配置文件。 設置管理器在adobe提供的網頁上設置,地址為www.adobe.com/go/settingsmanager_cn 。 裡面說明很詳細,配置起來也很簡單。 如圖:
這裡選擇始終允許可以禁止彈出那個煩人的警告框。
網站設置和作者設置為網絡權限:
網站設置即創建跨域文件。 作者設置即使用Security.allowDomain()方法。
限製網絡API
通過設置flash控件的alowNetworking可以限制as腳本與網絡的通信。 值如下:
"all"─允許使用所有as中的網絡API 默認值。
"internal"─不能調用瀏覽器導航或瀏覽器交互API。
"none"─ 禁止使用任何網絡通信,包括調用API,swf之間通信,超鏈接和使用共享庫。
允許腳本訪問:
允許as中的網絡API後,還要設置flash控件的allowScriptAccess,才能調用容器API或網頁腳本。 allowScriptAccess值如下:
“sameDomain”:swf與網頁必須位於同一域。 才能訪問腳本。 默認值。
“always”:不限制腳本訪問。
“never”:禁止腳本訪問。
全屏安全限制:
要使用全屏模式必須把flash控件的allowFullScreen屬性設置為true。 為防止惡意用戶打開網頁自動全屏,只有flash控件接受了鼠標事件或鍵盤事件後猜允許全屏。 通過dispachEvent發出的事件是不被認可的。
2012年11月9日 星期五
讓TexieField預設焦點並閃爍文字游標
有一個具有輸入功能的文字欄位,點選便可開始輸入文字
如果想要對使用者貼心一點的功能:不用點選就可以輸入,該怎麼做?
如果想要對使用者貼心一點的功能:不用點選就可以輸入,該怎麼做?
當文字欄位的容器增加至場景上時(stage或container),設定stage.focus屬性
stage.focus=文字欄位;
也可預設選取文字
textField.setSelection(0,0);
setSelection
() 方法 public function setSelection(beginIndex:int, endIndex:int):void
語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4
會根據第一個和最後一個字元指定的索引值 (以beginIndex和endIndex參數指定),設定選取文字。 如果這兩個參數值相同,這個方法便會設定插入點,就像是設定caretIndex屬性一樣。
參數
beginIndex:int— 選取範圍中第一個字元的索引值 (從零開始,例如,第一個字元是 0,第二個字元是 1,依此類推)。endIndex:int— 選取範圍中最後一個字元的索引值 (從零開始)。
2012年10月19日 星期五
訂閱:
文章 (Atom)