Load a new page in JavaFX webview - javascript

I am currently working on a Java application that uses a JavaFX webview to display its UI (with HTML/CSS).
Everything is working fine but I have trouble loading a new page in the system. When I do, the communication between the Java and the new page's JavaScript seems to be broken.
Here is my code :
** Broser **
public class Browser extends Region {
final WebView browser = new WebView();
final WebEngine webEngine = browser.getEngine();
public Browser() {
//apply the styles
getStyleClass().add("browser");
// load the web page
webEngine.load(some_url);
JSObject jsobj = (JSObject) webEngine.executeScript("window");
Bridge bridge = Bridge.getInstance();
bridge.init(webEngine);
jsobj.setMember("java", bridge);
//add the web view to the scene
getChildren().add(browser);
}
}
** Bridge **
public class Bridge {
private static Bridge instance = null;
private WebEngine webEngine;
public Bridge () {
}
public static Bridge getInstance() {
if(instance == null){
instance = new Bridge();
}
return instance;
}
public void init(WebEngine webEngine) {
if(this.webEngine == null) {
this.webEngine = webEngine;
}
}
public void btnStartSessionOnClick(String sessionName, String speakerNickname) {
// Load the new page
webEngine.load(some_other_url);
}
}

Whenever the web engine loads a new page, it replaces the DOM, so there is a different window object. The jsobj you define is only set once, so when a new page is loaded it will be pointing to the wrong object. You need to reset this object every time the page loads, which you can do by observing the engine's load state.
Your design doesn't make a whole lot of sense to me: it makes more sense to me to have the window (jsobj) object as part of the Bridge class, rather than the application class. And since the Browser is not a singleton, it doesn't make sense to make the Bridge a singleton (what if you had multiple web views in your application, for example?).
Here's an SSCCE:
package application;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class WebViewTest extends Application {
#Override
public void start(Stage primaryStage) {
WebView webView = new WebView();
WebEngine engine = webView.getEngine();
Label output = new Label();
Bridge bridge = new Bridge(engine);
engine.load(getClass().getResource("/resources/First.html").toExternalForm());
Button first = new Button("Load First");
first.setOnAction(e -> engine.load(getClass().getResource("/resources/First.html").toExternalForm()));
Button second = new Button("Load Second");
second.setOnAction(e -> engine.load(getClass().getResource("/resources/Second.html").toExternalForm()));
TextField textField = new TextField();
Button button = new Button("Send");
EventHandler<ActionEvent> handler = e -> {
bridge.execute(result -> output.setText(result.toString()),
"showText", textField.getText());
textField.setText("");
};
button.setOnAction(handler);
textField.setOnAction(handler);
HBox controls = new HBox(5, first, second, textField, button, new Label("Web page says: "), output);
controls.setPadding(new Insets(10));
BorderPane root = new BorderPane(webView, null, null, controls, null);
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
The Bridge class:
package application;
import java.util.function.Consumer;
import javafx.concurrent.Worker.State;
import javafx.scene.web.WebEngine;
import netscape.javascript.JSObject;
public class Bridge {
private JSObject window ;
public Bridge(WebEngine engine) {
engine.getLoadWorker().stateProperty().addListener((obs, oldState, newState) -> {
if (newState == State.SUCCEEDED) {
window = (JSObject) engine.executeScript("window");
window.setMember("application", this);
}
});
}
public void execute(Consumer<Object> callback, String function, Object... args) {
callback.accept(window.call(function, args));
}
}
And some simple test HTML files, which I have in a resources folder in the root of the classpath.
First.HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>First</title>
<script>
function showText(text) {
document.getElementById("text").innerHTML = text;
return text;
}
</script>
</head>
<body>
<p>This is the first page</p>
Go to the second page
<div id="text"></div>
</body>
</html>
and Second.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Second</title>
<script>
function showText(text) {
document.getElementById("text").innerHTML = text;
return text;
}
</script>
</head>
<body>
<p>This is the second page</p>
Go back to the first page
<div id="text"></div>
</body>
</html>

Related

Does new versions of google map's javascript versions work on JavaFx-WebView

I am trying to load google map on JavaFx-WebView, and it doesn't show anything except background color of html body that i have coded on html file.
Also i tried some examples on Google search, all the result were older. None of it works.
My Java version is "1.8.0_121"
I wrote a html file & run it. It loaded google maps successfully.
Then i load the html file to webview using webEngine.load("path") method.
it doesn't show anything except backgound color.
After that I tried
http://rterp.github.io/GMapsFX
runs ClusteredMainApp.java (put my google api key)
consoles outputs are:
"hier"
"clustererimages/m"
"Hide directions called"
"loadMapLibrary"
"loadMapLibrary done"
"initMap"
"LatLong: (47.606189, -122.33584200000001)"
"netscape.javascript.JSException: Error: The Google Maps JavaScript
API does not support this browser. (undefined,0)"
Also i couldn't find any solutions for this error
Html File
CSS:
#map_canvas { height: 100%; background-color: blue; }
javascript:
function initialize() {
var latlng = new google.maps.LatLng(37.39822, -121.9643936);
var myOptions = {
zoom: 14,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
navigationControl: false,
streetViewControl: false,
backgroundColor: "#666970"
};
document.geocoder = new google.maps.Geocoder();
document.map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
html:
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
JavaFX:
public class WebMap extends Application {
#Override public void start(Stage stage) {
// create web engine and view
final WebView webView = new WebView();
final WebEngine webEngine = webView.getEngine();
webEngine.load(getClass().getResource("WebMap.html").toString());
// create scene
stage.setTitle("Web Map");
Scene scene = new Scene(webView,1000,700, Color.web("#666970"));
stage.setScene(scene);
// show stage
stage.show();
}
public static void main(String[] args){
Application.launch(args);
}
}
Google maps API dropped support for older browsers which started causing the "The Google Maps JavaScript API does not support this browser." error. Look at https://developers.google.com/maps/documentation/javascript/releases and https://developers.google.com/maps/documentation/javascript/versions.
The library you are using is using version 3.exp (experimental).
Running on a newer Java version will fix this (for now).
If you want to use GMapsFX you can download the sample code from your link.
If you look closer you will see the lib got an class GoogleMapView and this contains is own WebView
some code from GMapsFX
public class GoogleMapView extends AnchorPane {
private static final Logger LOG = LoggerFactory.getLogger(GoogleMapView.class);
protected static final String GOOGLE_MAPS_API_LINK = "https://maps.googleapis.com/maps/api/js?v=3.exp";
protected static final String GOOGLE_MAPS_API_VERSION = "3.exp";
private boolean usingCustomHtml;
protected String language;
protected final String region;
protected String key;
protected WebView webview; <-- Own WebView
protected JavaFxWebEngine webengine;
protected boolean initialized = false;
protected final CyclicBarrier barrier = new CyclicBarrier(2);
protected final List<MapComponentInitializedListener> mapInitializedListeners = new ArrayList<>();
protected final List<MapReadyListener> mapReadyListeners = new ArrayList<>();
protected GoogleMap map;
protected DirectionsPane direc;
protected boolean disableDoubleClick = false;
So if you want to use the lib you should not create your own WebView.
You could start with the Sample
import com.lynden.gmapsfx.GoogleMapView;
import com.lynden.gmapsfx.javascript.event.GMapMouseEvent;
import com.lynden.gmapsfx.javascript.event.UIEventType;
import com.lynden.gmapsfx.javascript.object.GoogleMap;
import com.lynden.gmapsfx.javascript.object.LatLong;
import com.lynden.gmapsfx.javascript.object.MapOptions;
import com.lynden.gmapsfx.javascript.object.MapTypeIdEnum;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.web.WebView;
public class LatLongFXMLController implements Initializable {
#FXML
private Label latitudeLabel;
#FXML
private Label longitudeLabel;
#FXML
private GoogleMapView googleMapView;
private GoogleMap map;
private DecimalFormat formatter = new DecimalFormat("###.00000");
#Override
public void initialize(URL url, ResourceBundle rb) {
googleMapView.addMapInitializedListener(() -> configureMap());
}
protected void configureMap() {
MapOptions mapOptions = new MapOptions();
mapOptions.center(new LatLong(47.6097, -122.3331))
.mapType(MapTypeIdEnum.ROADMAP)
.zoom(9);
map = googleMapView.createMap(mapOptions, false);
map.addMouseEventHandler(UIEventType.click, (GMapMouseEvent event) -> {
LatLong latLong = event.getLatLong();
latitudeLabel.setText(formatter.format(latLong.getLatitude()));
longitudeLabel.setText(formatter.format(latLong.getLongitude()));
});
}
}

Applet class is not loading in a JSP

I'm working on maven web application with JSP and Servlets. I have a href which has a applet class call which loads my applet success fully from certain Servlet but on my windows only. Now I want to load this into client browser wherever this link is clicked from remote machine's IP. Please help me on this it should be loaded on client browser from HTML or JSP.
This is my class in my Java:
package com.enidiris.util;
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
public class AppletIris extends JApplet {
/**
*
*/
private static final long serialVersionUID = 1L;
private boolean inAnApplet = true;
public AppletIris() {
this(true);
}
public AppletIris(boolean inAnApplet) {
this.inAnApplet = inAnApplet;
if (inAnApplet) {
getRootPane().putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
}
}
public void init() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createGUI();
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void createGUI() {
MainPanel mainPanel = new MainPanel();
getContentPane().add(mainPanel);
}
}
This is my HTML in same web application but nothing says in console of browsers, not even loading applet.
webapp/ register.jsp
<body onload="checkSession();">
<jsp:plugin type="applet" name="AppletIris" code="com.enidiris.util.AppletIris" width="950" height="650" hspace="0" vspace="0" codebase="." >
</jsp:plugin>
<!-- <object codetype="application/java" classid="java:AppletIris.class" -->
<!-- archive="enidiris-applet.jar" width="740" height="400"></object> -->
</body>

(Apache Wicket) Set java atrribute from a js function

I am brand new on Apache Wicket and I need to set value on a Java attribute. This value comes from a var on JS filled by a specific function from a specific GIS lib (https://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html). This setting must be triggered by some component behavior.
Here is a simplified example code:
Wicket web page:
public class MapPage extends WebPage {
private static final long serialVersionUID = 1L;
private Integer coordinates;
// getters and setters
}
Wicket html:
<html xmlns:wicket="http://wicket.apache.org">
<head>
<!-- metas, scripts, and css imports -->
</head>
<body>
<script>
// component declarations
var coordinates = ''
map.on('draw:edited', function (e) {
e.layers.eachLayer(function(layer) {
coordinates = toWKT(layer);
// send coordinates to coordinates java attribute ??? how??
});
});
</script>
</body>
Thanks a lot!
This is a piece of code from one of my projects, where I want to handle a click on a (HighCharts) chart. It passes data to Wicket and Wicket then updates another panel to display details related to the click.
The relevant javascript part, where interactionurl is actually the callbackScript that is generated by the behavior later on:
interactionurl(JSON.stringify(myDataToPass));
The behaviour:
this.add( this.interactionbehavior = new AbstractDefaultAjaxBehavior()
{
#Override
protected void respond( final AjaxRequestTarget target )
{
RequestCycle cycle = RequestCycle.get();
WebRequest webRequest = (WebRequest) cycle.getRequest();
String param1 = webRequest.getQueryParameters().getParameterValue( "mydict" ).toString( "" );
//param1 contains the JSON map passed from javascript.
//you can also do stuff now, like replacing components using ajax
}
#Override
protected void updateAjaxAttributes( AjaxRequestAttributes attributes )
{
super.updateAjaxAttributes( attributes );
attributes.getExtraParameters().put( "mydict", "__PLACEHOLDER__" );
}
#Override
public CharSequence getCallbackScript()
{
String script = super.getCallbackScript().toString().replace( "\"__PLACEHOLDER__\"", "data" );
return script;
}
} );
You only need to pass the interaction url to the page on some moment. For this you can use renderHead in the component that has the behaviour:
#Override
public void renderHead( final IHeaderResponse response )
{
...
//use the `setupCallback` to store the callback script somewhere.., I store it in 'interactionurl'
String script = String.format( " setupCallback(this.interactionbehavior.getCallbackScript()); ");
response.render( OnDomReadyHeaderItem.forScript( script )
}

Create a tool to open local pdf files on android tablet

I'm sorry if this is a stupid question, but my knowledge is very limited on this subject. I'm not asking for a complete solution, I just need a little push in the right direction.
I have an adroid tablet with a lot of pdf files on the sdcard. Now I want to make a tool to scan a barcode with the filename and open this pdf file. The barcode will be like test and the corresponding file will be file://sdcard/pdf/test.pdf.
The barcode scanner gives an enter after scanning so I only need a textbox on screen and the enter key to initiate the opening activity. We'd rather not connect this tablet to our network, so it doesn't have an internet connection.
I have tried to make an app for this, but since my android programming skills are pretty limited this didn't work out for me.
Now I am trying to make a web app with either php or javascript. This isn't really working out for me since my experience with either of those is limited as well. Initially I was thinking of an MS Access tool in VBA but since there's no runtime for Android this idea doesn't work out.
I've already searched for a solution, but haven't found anything I could use.
Does anyone have a suggestion on with kind of tool I should use? And perhaps put me in the right direction. For more information, please ask.
UPDATE 1:
Right now I've created a webpage using HTML and JavaScript. My code is as the following:
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=windows-1252" http-equiv="content-type">
<script type="text/javascript">
function clickyClick() {
url = 'file:///mnt/sdcard/documents/instructies/' + document.getElementById("barcode").value + '.pdf'
window.open(url, '_blank');
document.getElementById("barcode").value = "";
}
</script> <title>Open werkinstructie</title>
</head>
<body>
<form><span style="font-weight: bold; font-family: Helvetica,Arial,sans-serif; font-size:50px;">Barcode:</span>
<input autofocus="autofocus" style="font-size:50px" name="barcode" id="barcode"
onkeydown="if (event.which == 13) clickyClick()" type="text"> </form>
<br>
<button style="height: 85px; width: 120px; font-size: 30px; font-weight:bold;"
onclick="clickyClick()">Open</button>
</body>
</html>
Which I open with Firefox on the tablet. For now I can't get it to work using the Barcode scanner or the enter key, the button however does work. This code opens the file in Adobe Reader, which is exactly what I want to do.
UPDATE 2:
MainActivity.java:
package com.example...............;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
final String TAG = null;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText mEditText = (EditText) findViewById(R.id.editText1);
mEditText.setImeActionLabel("Klaar", KeyEvent.KEYCODE_ENTER);
EditText.OnEditorActionListener exampleListener = new EditText.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
Log.d(TAG, "onEditorAction, key=" + event.getKeyCode() + " action=" + event.getAction());
if (event.getAction() == KeyEvent.KEYCODE_ENTER) {
openPDF(mEditText.toString());
mEditText.setText("");
}
return true;
}
};
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private void openPDF(String fileName){
String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
File file = new File(baseDir + File.separator + "documents/instructies/"+fileName+".pdf");
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "No reader",
Toast.LENGTH_SHORT).show();
}
}
}
}
UPDATE 3:
MainActivity.java
package com.example..............;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
final String LOG_TAG = "MainActivity";
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText mEditText = (EditText) findViewById(R.id.editText1);
mEditText.setImeActionLabel("Klaar", KeyEvent.KEYCODE_ENTER);
mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.d(LOG_TAG, "onEditorAction, key=" + event.getKeyCode() + "action =" + event.getAction());
if (event.getAction() ==1 && event.getKeyCode() ==66) {
String Text = mEditText.getText().toString();
openPDF(Text);
mEditText.setText("");
}
return true;
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private void openPDF(String fileName) {
File file = new File("sdcard/documents/instructies/" + fileName + ".pdf");
//File file = new File("sdcard/documents/instructies/0195476.pdf");
//final String LOG_TAG_2 = "MainActivity";
//Log.d(LOG_TAG_2, "exist = " + file.exists());
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "No reader",
Toast.LENGTH_SHORT).show();
}
}
}
}
In your layout add an EditText as this:
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
>
<requestFocus />
</EditText>
In your activity add this in onCreate method:
final EditText mEditText = (EditText) findViewById(R.id.editText1);
mEditText.setImeActionLabel("Done", KeyEvent.KEYCODE_ENTER);
EditText.OnEditorActionListener exampleListener = new EditText.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
Log.d(TAG, "onEditorAction, key="+event.getKeyCode() + " action="+event.getAction());
if (event.getAction() == KeyEvent.KEYCODE_ENTER) {
openPDF(mEditText.toString());
}
return true;
}
};
To open a PDF, install a PDF app from market and in your activity open PDF as this:
private void openPDF(String fileName){
File file = new File("/sdcard/pdf/"+fileName+".pdf");
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "No reader",
Toast.LENGTH_SHORT).show();
}
}
}

Get the local file path through actionscript (or Javascript)

I have a scenario where the user clicks on a menu item in a flex application, that menu item is supposed to give them the file browser on their OS (Mac OSX for now) and then once they choose the file, I pass that file's local path along to another part of the application (that's already written) which makes a connection using that.
I've done some research and found code that can only be used if I include the AIR SDK which I prefer not to, is there a way to do this in actionscript or javascript (since I can call javascript from my actionscript application)?
Edit: the service I am passing the path to requires having the full local path which means that after browsing files, I have to get the local path to pass it along!
Without using AIR, you can still spawn a file browse dialog for uploading local files using the FileReference class with a Flex or pure ActionScript project.
This can be abstracted to a service class.
Application
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
protected function buttonClickHandler(event:MouseEvent):void
{
var uploadService:UploadService = new UploadService("http://destination.com");
uploadService.browse();
}
]]>
</fx:Script>
<s:Button label="Upload..."
click="buttonClickHandler(event)" />
</s:Application>
Upload Service
package
{
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.net.FileFilter;
import flash.net.FileReference;
import flash.net.URLRequest;
public class UploadService extends EventDispatcher
{
public var fileReference:FileReference;
public var fileTypes:FileFilter;
public var uri:String
public function UploadService(uri:String)
{
this.uri = uri;
}
public function browse():void
{
fileTypes = new FileFilter("* (*.*)", "*.*;");
var allTypes:Array = new Array(fileTypes);
fileReference = new FileReference();
fileReference.addEventListener(Event.SELECT, fileSelectHandler);
fileReference.addEventListener(Event.OPEN, fileOpenHandler);
fileReference.addEventListener(Event.COMPLETE, fileCompleteHandler);
fileReference.addEventListener(SecurityErrorEvent.SECURITY_ERROR, fileSecurityErrorHandler);
fileReference.addEventListener(IOErrorEvent.IO_ERROR, fileIoErrorHandler);
fileReference.browse(allTypes);
}
protected function fileSelectHandler(event:Event):void
{
fileReference.upload(new URLRequest(uri));
}
protected function fileOpenHandler(event:Event):void
{
dispatchEvent(new Event(Event.OPEN));
}
protected function fileCompleteHandler(event:Event):void
{
fileReference.removeEventListener(Event.SELECT, fileSelectHandler);
fileReference.removeEventListener(Event.OPEN, fileOpenHandler);
fileReference.removeEventListener(Event.COMPLETE, fileCompleteHandler);
fileReference.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, fileSecurityErrorHandler);
fileReference.removeEventListener(IOErrorEvent.IO_ERROR, fileIoErrorHandler);
dispatchEvent(new Event(Event.COMPLETE));
}
protected function fileSecurityErrorHandler(event:SecurityErrorEvent):void
{
dispatchEvent(new SecurityErrorEvent(SecurityErrorEvent.SECURITY_ERROR));
}
protected function fileIoErrorHandler(event:IOErrorEvent):void
{
dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR));
}
}
}

Categories