Flex3 load flashpaper uses LocalConnection to communicate with flash

Source: Internet
Author: User
Code

Package com. magReader
{

Import flash. events. Event;
Import flash. events. StatusEvent;
Import flash.net. LocalConnection;
// Import flash. system. System;

Import mx. controls. SWFLoader;

/**
* UIComponent designed specifically to load FlashPaper documents
* And size them correctly in the available area.
*/
Public class FlashPaperLoader extends SWFLoader
{

/**
* The id of the FlashPaperLoader.swf proxy that will be used
* For communication pyurposes.
*/
Public static const FLASH_PAPER_LOADED: String = "flashPaperLoaded ";
Public static const FLASH_CONNERROR: String = "flashConnError ";
Private var sendFlashConn: LocalConnection;
Private var recieveFlashConn: LocalConnection;
/**
* The name of the application that is loading in the FlashPaperLoader.swf
* File. This name must correspond to the "id" attribute in the object tag
* And the "name" attribute in the embed tag when the Flex client is embedded
* Into the html page.
*/

/**
* Constructor
*/
Public function FlashPaperLoader ()
{
// Source = "app-storage:/data/fpHolder.swf ";
SendFlashConn = new LocalConnection ();
RecieveFlashConn = new LocalConnection ();
RecieveFlashConn. client = this;
Sendflashconn. addeventlistener (statusevent. Status, onstatus );
Sendflashconn. allowdomain ("*");
Recieveflashconn. allowdomain ("*");
Sendconn ();
}
Public Function sendconn (): void
{
Try
{
RecieveFlashConn. connect ("_ flexloader ");
} Catch (error: ArgumentError ){
Trace ("Can't connect... the connection name is already being used by another SWF ");
OnConnError ();
Return;
}
}

Private function onStatus (result: StatusEvent): void {

Trace (result. level = "error "? "Operation failed": "Operation succeeded ");

}
// Connection source Error
Private function onConnError (): void
{
// ErrUnload ();

Var e: Event = new Event (FlashPaperLoader. FLASH_CONNERROR );
DispatchEvent (e );
}

// ================================================ ======================================
// Expose methods that are proxied from flashpaperloader.swf-call
// Javascript methods that the flashpaperloader.swf file picks up
// And passes to the loaded flashpaper document.
// ================================================ ======================================

Public Function setsize (width: Number, height: Number): void
{
Trace ("========= setpapersize ================ ");
Sendflashconn. Send ("_ flashpaperloader", "setpapersize", width, height );
}
/**
* Prompt for successful document loading
**/
Public function fpLoaded (): void
{
Trace ("reveice fpLoaded message !! This. width = "+ this. width +" this. height "+ this. height );
// SetSize (parent. width, parent. height );
Var e: Event = new Event (FlashPaperLoader. FLASH_PAPER_LOADED );
DispatchEvent (e );
// This. visible = true;
}
/**
* Set Scaling
**/
Public function setZoom (value: Object): void
{
If (this. visible)
{
SendFlashConn. send ("_ flashpaperloader", "setCurrentZoom", value );
}
}

// Override protected function updateDisplayList (unscaledWidth: Number,
// UnscaledHeight: Number): void
//{
// If (contentHolder)
//{
/// Adjust values so the FlashPaper document is displayed correctly
// ContentHolder. scalex= 1.0;
// ContentHolder. scaleY = 1.0;
// ContentHolder. x = 0;
// ContentHolder. y = 0;
//
// ContentHolder. scrollRect = new Rectangle (0, 0, unscaledWidth, unscaledHeight );
//
/// When the content has loaded, call the setSize method so that
/// FlashPaper document sizes right in the available area
// If (Loader (contentHolder). content)
//{
// SetSize (unscaledWidth, unscaledHeight );
/// This. setFocus ();
//}
//}
//}

// Uninstall this SWF
Public Function unload (): void
{
If (sendflashconn! = NULL)
{
Sendflashconn. Send ("_ flashpaperloader", "Unload ");
Sendflashconn = NULL;
}
Try
{
If (recieveflashconn! = NULL)
{
Recieveflashconn. Close ();
RecieveFlashConn = null;
}
} Catch (e: ArgumentError)
{
Trace (e. toString ());
RecieveFlashConn = null;
}

Unloadandstop (true );
// System. GC ();
}
Public Function errunload (): void
{
If (sendflashconn! = NULL)
{
SendFlashConn. send ("_ flashpaperloader", "unload ");
SendFlashConn = null;
}
If (recieveFlashConn! = Null) recieveFlashConn = null;
UnloadAndStop (true );
// System. gc ();
}

} // End class
} // End package

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.