Closed GoogleCodeExporter closed 9 years ago
Amendment to above - as it contained an error - please remove if possible:
I'd like to start by saying, thank you for submitting the extension to
StageWebView - if I can get it working for me it really will save a lot of time
- especially as I can access native mobile widgets.
Ultimately I want to access local html files. Before I started I read the
documentation and the examples, which I believe I followed; however without
sucess.
Attempt One - Load http://www.google.com
This is the code in the default (first view) of a Flex Mobile App:
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
title="HomeView"
addedToStage="view1_addedToStageHandler(event)">
<fx:Script>
<![CDATA[
import es.xperiments.media.StageWebViewBridge;
import es.xperiments.media.StageWebViewBridgeEvent;
import es.xperiments.media.StageWebViewDisk;
import es.xperiments.media.StageWebviewDiskEvent;
import spark.events.ViewNavigatorEvent;
protected var webView:StageWebViewBridge = new StageWebViewBridge(20, 100, 450, 450);
protected function view1_addedToStageHandler(event:Event):void
{
sve.addChild(webView);
webView.addEventListener(LocationChangeEvent.LOCATION_CHANGE,onURLChange);
webView.loadURL("http://www.google.co.uk");
addEventListener(ViewNavigatorEvent.REMOVING, onRemove);
}
protected function onURLChange(event:LocationChangeEvent):void
{
trace("URL change " + event.location);
// Uncomment the following line to load in the default browser instead...
//navigateToURL(new URLRequest(event.location));
}
protected function onRemove(event:ViewNavigatorEvent):void
{
this.webView.dispose();
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:SpriteVisualElement id="sve"/>
</s:View>
These are the error messages I am getting:
URL change http://www.google.co.uk/
ReferenceError: Can't find variable: StageWebViewBridge
ReferenceError: Can't find variable: google
at http://www.google.co.uk/ : 50
at http://www.google.co.uk/ : 50
at http://www.google.co.uk/ : 51
at http://www.google.co.uk/ : 58
at http://www.google.co.uk/ : 57
at http://www.google.co.uk/ : 62
at http://www.google.co.uk/ : 24
The page is rendered however. But if I try and click on any links (for instance
the images link), I get the following error:
TypeError: Error #1034: Type Coercion failed: cannot convert
es.xperiments.media::StageWebViewBridge@3199ba1 to
flash.display.InteractiveObject.
at mx.managers::FocusManager/focusInHandler()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\FocusManager.as:610]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at es.xperiments.media::StageWebViewBridge/onListener()[/Users/xperiments/Documents/workspace/StageWebViewBridge/src/es/xperiments/media/StageWebViewBridge.as:162]
at flash.html::HTMLLoader/nativeFocusIn()
at flash.html::HTMLLoader/getFocusIfNeeded()
at flash.html::HTMLLoader/invokeMouseDownImpl()
at flash.html::HTMLLoader/onLeftMouseDown()
Attempt Two - Load A Local File
I created a folder called "www" in the root of the project and added a simple
html file - called index.html. I tried lots of things, but had no luck at all.
Following the examples you've provided I came up with, code which is identical
to above, except I changed the loadurl to loadlocalurl, as you can see below:
protected function view1_addedToStageHandler(event:Event):void
{
sve.addChild(webView);
webView.addEventListener(LocationChangeEvent.LOCATION_CHANGE,onURLChange);
webView.loadLocalURL("applink:/index.html");
addEventListener(ViewNavigatorEvent.REMOVING, onRemove);
}
I get the following error messages:
TypeError: Error #1009: Cannot access a property or method of a null object
reference.
at es.xperiments.media::StageWebViewDisk$/getFilePath()[/Users/xperiments/Documents/workspace/StageWebViewBridge/src/es/xperiments/media/StageWebViewDisk.as:190]
at es.xperiments.media::StageWebViewBridge/loadLocalURL()[/Users/xperiments/Documents/workspace/StageWebViewBridge/src/es/xperiments/media/StageWebViewBridge.as:280]
at views::ZZZSpinner2HomeView/view1_addedToStageHandler()[C:\Users\parmy\Adobe Flash Builder 4.5\ZZZSpinner2\src\views\ZZZSpinner2HomeView.mxml:21]
at views::ZZZSpinner2HomeView/___ZZZSpinner2HomeView_View1_addedToStage()[C:\Users\parmy\Adobe Flash Builder 4.5\ZZZSpinner2\src\views\ZZZSpinner2HomeView.mxml:4]
at flash.display::DisplayObjectContainer/addChildAt()
at mx.managers::SystemManager/preloader_preloaderDoneHandler()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\SystemManager.as:2670]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.preloaders::Preloader/displayClassCompleteHandler()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\preloaders\Preloader.as:582]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at spark.preloaders::SplashScreen/dispatchComplete()[E:\dev\4.5.1\frameworks\projects\mobilecomponents\src\spark\preloaders\SplashScreen.as:520]
at spark.preloaders::SplashScreen/preloader_initCompleteHandler()[E:\dev\4.5.1\frameworks\projects\mobilecomponents\src\spark\preloaders\SplashScreen.as:489]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.preloaders::Preloader/dispatchAppEndEvent()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\preloaders\Preloader.as:380]
at mx.preloaders::Preloader/appCreationCompleteHandler()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\preloaders\Preloader.as:590]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:13128]
at mx.core::UIComponent/set initialized()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:1818]
at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:842]
at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1180]
I looked further into your documentation, and it seems to suggest
StageWebViewDisk is set up first. So I changed my code to the following:
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
title="HomeView"
addedToStage="view1_addedToStageHandler(event)">
<fx:Script>
<![CDATA[
import es.xperiments.media.StageWebViewBridge;
import es.xperiments.media.StageWebViewBridgeEvent;
import es.xperiments.media.StageWebViewDisk;
import es.xperiments.media.StageWebviewDiskEvent;
import flash.media.StageWebView;
import spark.events.ViewNavigatorEvent;
protected var webView:StageWebViewBridge = new StageWebViewBridge(20, 100, 450, 450);
protected function view1_addedToStageHandler(event:Event):void
{
// OPTIONAL BEFORE INIT OPTIONS SETTING
StageWebViewDisk.setDebugMode( true );
// if we need debug mode assign it before initializaton
// StageWebViewDisk Events. First time app launches it proceses the filesystem
// As it can take some time, depending of the filesize of the included files
// we provide 2 events to know when process start/finish
StageWebViewDisk.addEventListener(StageWebviewDiskEvent.START_DISK_PARSING, onDiskCacheStart);
StageWebViewDisk.addEventListener(StageWebviewDiskEvent.END_DISK_PARSING, onDiskCacheEnd);
StageWebViewDisk.initialize( this.stage );
}
protected function onDiskCacheStart(e:StageWebViewBridgeEvent):void {
trace("SWVD parsing started");
}
protected function onDiskCacheEnd(e:StageWebViewBridgeEvent):void {
trace("SWVD parsing ended");
webView.addEventListener(Event.ADDED_TO_STAGE, tempHandler);
sve.addChild(webView);
}
protected function tempHandler(e:Event):void {
//webView.viewPort = new Rectangle(20, 100, 450, 450);
webView.addEventListener(LocationChangeEvent.LOCATION_CHANGE,onURLChange);
//webView.loadURL("http://www.google.co.uk");
webView.loadLocalURL("applink:/index.html");
addEventListener(ViewNavigatorEvent.REMOVING, onRemove);
}
protected function onURLChange(event:LocationChangeEvent):void
{
trace("URL change " + event.location);
// Uncomment the following line to load in the default browser instead...
//navigateToURL(new URLRequest(event.location));
}
protected function onRemove(event:ViewNavigatorEvent):void
{
this.webView.dispose();
}
]]>
</fx:Script>
<s:SpriteVisualElement id="sve"/>
</s:View>
I now get the following error:
Error: Error #2037: Functions called in incorrect sequence, or earlier call was
unsuccessful.
at Error$/throwError()
at flash.filesystem::File/resolveComponents()
at flash.filesystem::File/resolvePath()
at es.xperiments.media::StageWebViewDisk$/initialize()[/Users/xperiments/Documents/workspace/StageWebViewBridge/src/es/xperiments/media/StageWebViewDisk.as:102]
at views::ZZZSpinner2HomeView/view1_addedToStageHandler()[C:\Users\parmy\Adobe Flash Builder 4.5\ZZZSpinner2\src\views\ZZZSpinner2HomeView.mxml:31]
at views::ZZZSpinner2HomeView/___ZZZSpinner2HomeView_View1_addedToStage()[C:\Users\parmy\Adobe Flash Builder 4.5\ZZZSpinner2\src\views\ZZZSpinner2HomeView.mxml:5]
at flash.display::DisplayObjectContainer/addChildAt()
at mx.managers::SystemManager/preloader_preloaderDoneHandler()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\SystemManager.as:2670]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.preloaders::Preloader/displayClassCompleteHandler()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\preloaders\Preloader.as:582]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at spark.preloaders::SplashScreen/dispatchComplete()[E:\dev\4.5.1\frameworks\projects\mobilecomponents\src\spark\preloaders\SplashScreen.as:520]
at spark.preloaders::SplashScreen/preloader_initCompleteHandler()[E:\dev\4.5.1\frameworks\projects\mobilecomponents\src\spark\preloaders\SplashScreen.as:489]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.preloaders::Preloader/dispatchAppEndEvent()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\preloaders\Preloader.as:380]
at mx.preloaders::Preloader/appCreationCompleteHandler()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\preloaders\Preloader.as:590]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:13128]
at mx.core::UIComponent/set initialized()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:1818]
at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:842]
at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1180]
I completely at a loss here. Your solution would be fantastic for so many
things - I just wish I could get the basics working first before I get onto the
cool callback stuff.
Do you have any suggestions?
If you need anything else from me please let me know, I can attach the .fxp if
required.
Thanks in advance.
Cheers
Parmy
Original comment by parmyb...@gmail.com
on 27 Sep 2011 at 12:39
Hi,
You have 2 errors in your last code...
protected function onDiskCacheStart(e:StageWebViewBridgeEvent):void {
trace("SWVD parsing started");
}
StageWebViewBridgeEvent should be StageWebviewDiskEvent...
The other problem:
Type Coercion failed: cannot convert
es.xperiments.media::StageWebViewBridge@3199ba1 to
flash.display.InteractiveObject.
This problem occurs because the container must extend UIComponent and have
focusEnabled assigned to false....
Anyway I attach a working copy of your code as .fxp.
See the SWVBUIComponent class I have provided...
Original comment by xperime...@gmail.com
on 27 Sep 2011 at 1:50
Attachments:
Original comment by xperime...@gmail.com
on 27 Sep 2011 at 1:51
Thank you, that worked a treat - I look foward to putting the Bridge through
it's paces.
Cheers
Parmy
Original comment by parmyb...@gmail.com
on 27 Sep 2011 at 10:21
Original issue reported on code.google.com by
parmyb...@gmail.com
on 27 Sep 2011 at 12:32