Hey there!
I'm trying to load some local content inside a StageWebView but it looks like it's not working. Here are the docs about this feature.
I think I'm doing it the way I should but I may be wrong... Someone knows how?
Here's my code:
package { import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.ErrorEvent; import flash.events.Event; import flash.events.LocationChangeEvent; import flash.events.StageOrientationEvent; import flash.filesystem.File; import flash.geom.Rectangle; import flash.media.StageWebView; import flash.net.URLRequest; import net.tw.util.air.DownloadHelper; public class MobileSWFDownloader extends Sprite { protected var _downloader:DownloadHelper; protected var _swv:StageWebView; public function MobileSWFDownloader() { super(); stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; _downloader=new DownloadHelper(new URLRequest('http://toki-woki.net/lab/eM/test.html'), File.applicationStorageDirectory.resolvePath('local.html')); _downloader.stream.addEventListener(Event.COMPLETE, onDownloaded); _downloader.start(); } protected function onDownloaded(e:Event):void { _swv=new StageWebView(); _swv.addEventListener(ErrorEvent.ERROR, trace); _swv.addEventListener(LocationChangeEvent.LOCATION_CHANGE, trace); _swv.stage=stage; _swv.loadURL('file://'+_downloader.destination.nativePath); placeWebView(); stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, placeWebView); } protected function placeWebView(e:Event=null):void { _swv.viewPort=new Rectangle(0, 0, stage.stageWidth, stage.stageHeight); } } }
And here's the output:
[SWF] MobileSWFDownloader.swf - 4,161 bytes after decompression [LocationChangeEvent type="locationChange" bubbles=false cancelable=false eventPhase=2 location="file:///data/data/air.fr.edumedia.MobileSWFDownloader.debug/fr.edumedia.MobileSWFDownloader.debug/Local Store/local.html"]
Problem is: the StageWebView remains blank and doesn't seem to load anything...
Any idea why?
The DownloadHelper class is a simple utility that downloads a remote file and stores it locally, available here.
Thanks!