Handling Dialog and Menu Popups
This will walk you through the process of creating a temporary dynamic screenshot of your Flash App and replacing the Flash Object with this image within 200ms. This allows Dialogs to display correctly and creates a more pleasing user experience.
The How-To is divided into the following sections:
Creating a Dynamic Screenshot in Flash
Enabling ActionScript to JavaScript Communication
Using a Data URI
Setting up the hideFlashCallback Functionality
Source Code for the Example App
Developers are expected to be familiar with JavaScript and ActionScript 3.0 in order to continue.
Creating a Dynamic Screenshot in Flash
The first step will be to implement a method within your Flash App that creates a dynamic screenshot of the Stage object, compresses this into a JPEG format and then Base64 encodes this string. Fortunately there are public libraries available that will take care of most of these steps. For this example we will use: blooddy_crypto.swc or feel free to use any lib that you prefer.
Next we will create the ActionScript exportScreenshot method that will return our screenshot data string, ready for use.
ActionScript
import by.blooddy.crypto.Base64;
import by.blooddy.crypto.image.JPEGEncoder;
...
private function exportScreenshot():String {
var scale:Number = 0.25;
var result:String = null;
var blurFilter:BlurFilter = new BlurFilter(3, 3, BitmapFilterQuality.HIGH);
var bData:BitmapData = new BitmapData(stage.stageWidth * scale,
stage.stageHeight * scale,false,0x0);
var matrix:Matrix = new Matrix();
matrix.scale(scale, scale);
bData.draw(stage, matrix);
bData.applyFilter(bData, bData.rect, new Point(0, 0), blurFilter);
var jpgBytes:ByteArray = JPEGEncoder.encode(bData,80);
การจัดการโต้ตอบและเมนูป๊อปอัป
นี้จะเดินคุณผ่านขั้นตอนกระบวนการของการสร้างหน้าจอแบบไดนามิกชั่วคราวของ app แฟลชของคุณและแทนที่วัตถุแฟลชกับภาพนี้ภายใน 200ms นี้จะช่วยให้เพื่อแสดงกล่องโต้ตอบได้อย่างถูกต้องและสร้างประสบการณ์ของผู้ใช้ที่ชื่นชอบมากขึ้น
วิธีการแบ่งออกเป็นส่วนต่อไปนี้ :
การสร้างหน้าจอแบบไดนามิกในแฟลช
เปิดใช้งาน ActionScript
JavaScript โดยใช้ข้อมูลการสื่อสารการตั้งค่าฟังก์ชั่น hideflashcallback ยูริ
รหัสที่มาสำหรับตัวอย่างนักพัฒนา app
คาดว่าจะคุ้นเคยกับ JavaScript และ ActionScript 3.0 เพื่อต่อไป . . .
สร้างหน้าจอแบบไดนามิกในแฟลช
ขั้นตอนแรกจะใช้วิธีการภายใน App แฟลชของคุณที่สร้างหน้าจอแบบไดนามิกของระยะวัตถุ , บีบอัดเป็นรูปแบบ JPEG และ Base64 เข้ารหัสสตริงนี้ โชคดีมีห้องสมุดพร้อมที่จะดูแลส่วนใหญ่ของขั้นตอนเหล่านี้ สำหรับตัวอย่างนี้ เราจะใช้ : blooddy_crypto.swc หรือรู้สึกฟรีเพื่อใช้ lib ที่ชอบ
ต่อไปเราจะสร้าง ActionScript exportscreenshot วิธีที่จะกลับมาหน้าจอข้อมูลสตริง , พร้อมใช้งาน ActionScript .
นำเข้าโดย blooddy . การเข้ารหัส Base64 ;
. นำเข้าโดย blooddy . การเข้ารหัสลับ ภาพ . jpegencoder ;
. . . . . . .
ส่วนตัว exportscreenshot() ฟังก์ชันสตริง {
var = 0.25 ขนาด : หมายเลข ;
VAR ผล : สตริง = null ;
var blurfilter : blurfilter ใหม่ = blurfilter ( 3 , 3 , bitmapfilterquality สูง
) ;var ข้อมูล : bitmapdata ใหม่ = bitmapdata ( stage.stagewidth * ขนาด
stage.stageheight * ขนาด , เท็จ , 0x0 var ) ;
: เมทริกซ์เมทริกซ์ใหม่ = matrix() ;
เมตริกซ์ ขนาด ( ขนาดขนาด ) ;
ข้อมูล วาด ( Matrix เวที ) ;
ข้อมูล . applyfilter ( ข้อมูล bdata.rect , ใหม่ , จุด 0 , 0 ) , blurfilter ) ;
var jpgbytes : bytearray = ( jpegencoder . เข้ารหัสข้อมูล , 80 )
การแปล กรุณารอสักครู่..
