Implementing stageWebView in GestureWorks TouchSprite - actionscript-3

I am attempting to create a component in a GestureWorks AIR application that renders a stageWebView in a touchsprite container. Given the stageWebView is not a display object is this possible?
Below is the code:
package view
{
import com.gestureworks.core.GestureWorks;
import com.gestureworks.core.TouchSprite;
import com.gestureworks.events.GWGestureEvent;
import com.modestmaps.Map;
import com.modestmaps.events.MapEvent;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.geom.Rectangle;
import flash.media.StageWebView;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class webView extends TouchSprite
{
private var urlAddress:String = "http://google.com";
public var stageWebView:StageWebView = new StageWebView();
private var ts:TouchSprite;
public function webView()
{
super();
init();
}
private function init():void
{
ts = new TouchSprite();
ts.width = 500;
ts.height = 500;
ts.x = 200;
ts.y = 100;
ts.rotation = 45;
ts.scaleX = 0.5;
ts.scaleY = 0.5;
ts.gestureEvents = true;
ts.disableAffineTransform = false;
ts.gestureList = { "n-drag":true, "n-scale":true, "n-rotate":true };
ts.addEventListener(GWGestureEvent.DRAG, gestureDragHandler);
ts.addEventListener(GWGestureEvent.ROTATE, gestureRotateHandler);
ts.addEventListener(GWGestureEvent.SCALE, gestureScaleHandler);
if(StageWebView.isSupported == true)
{
stageWebView.stage = this.stage;
stageWebView.viewPort = new Rectangle(0,0, 500, 500);
//stageWebView.addEventListener(LocationChangeEvent.LOCATION_CHANGE, locationChangedHandler);
//stage.scaleMode = StageScaleMode.EXACT_FIT;
//this.stage.addEventListener(Event.RESIZE, resizeEvent);
getURL();
}
else
{
urlAddress = "StageWebView not supported";
}
ts.addChild(stageWebView as DisplayObject);
addChild(ts);
}
protected function getURL():void
{
stageWebView.loadURL(urlAddress);
//stageWebView.addEventListener(Event.COMPLETE,handleLoad);
}

No. Since StageWebView is not a display object, you can't add it to another object to be managed automatically.
You can manage it manually from the sprite--when the sprite is displayed, show the web view, when the sprite is resized, resize the web view, etc.
If your web view is covering up the entire TouchSprite once it's rendered, I'm fairly certain that your sprite won't receive gesture events--those would be handled by the native component.

Related

Starling cannot access a property or method of a null object reference

Hey any help appreciated i've been mind boggled by the asset manager for a couple of days
Here is my Hawaii class that I'm trying to reference assets from my asset manager class (MapAssetLoadQeue). and I'm getting the Cannot access a property or method of a null object reference. Error, the error is thrown in my Hawaii class if I don't (Null) the Asset Manager reference, and it is thrown in my Loader Class haw.showHawaii()
Thanks!!!
package Maps
{
import flash.filesystem.File;
import Enqueue.MapAssetLoadQeue;
import starling.animation.IAnimatable;
import starling.animation.Juggler;
import starling.core.Starling;
import starling.display.Image;
import starling.display.MovieClip;
import starling.display.Sprite;
import starling.events.Event;
import starling.textures.Texture;
import starling.textures.TextureAtlas;
import starling.utils.AssetManager;
public class Hawaii extends Sprite
{
public var mal:MapAssetLoadQeue = new MapAssetLoadQeue;
public var Ocean:Image;
public function Hawaii():void{
super();
this.addEventListener
(starling.events.Event.ADDED_TO_STAGE, showHawaii);
}
public function showHawaii(e:Event):void{
if(mal.mapAssets != null) {
Ocean = new Image(mal.mapAssets.getTexture("blue"));
addChild(Ocean);
Ocean.x = 0;
Ocean.y = 0;
}
}
Here is my loader class where I load my assets, and here is where I get my error. haw.showHawaii(null) function. Cannot access a property or method of a null object reference.
package Assets {
import flash.filesystem.File;
import Enqueue.MapAssetLoadQeue;
import GUI.Wave;
import Maps.Hawaii;
import starling.animation.IAnimatable;
import starling.animation.Juggler;
import starling.core.Starling;
import starling.core.starling_internal;
import starling.display.Image;
import starling.display.MovieClip;
import starling.display.Sprite;
import starling.events.Event;
import starling.textures.Texture;
import starling.textures.TextureAtlas;
import starling.utils.AssetManager;
public class Loader extends Sprite {
var loadText: Texture = Texture.fromEmbeddedAsset(loadMCTexture);
var loadXml: XML = XML(new loadMC0Xml());
var loaderAtlas: TextureAtlas = new TextureAtlas(loadText, loadXml);
public var loaderMovie: MovieClip = new MovieClip(loaderAtlas.getTextures("loading_"));
public var mal: MapAssetLoadQeue = new MapAssetLoadQeue;
public var wave:Wave = new Wave;
public var haw:Hawaii;
//Loader MovieClip size 720X233;
[Embed(source = "/../Wavehunter/loadScreenAssets/wm/MovieClips/loader/loader_0.xml", mimeType = "application/octet-stream")]
public static const loadMC0Xml: Class;
[Embed(source = "/../Wavehunter/loadScreenAssets/wm/MovieClips/loader/loader_0.png")]
public static const loadMCTexture: Class;
// public var juggler:Juggler = Starling.juggler;
/*
======================================================================
Every Movieclip asset for the worldMap
> Load WorldMap Assets on stage as Png and Make all alpha to 30%
> and within each function make that png invible to false or remove
> add MoviClip over the invisible png after load is processed
=======================================================================
*/
// Load WorldMap asset function
public function mapLoader(): void {
mal.requestWM();
addChild(loaderMovie);
loaderMovie.x = 347;
loaderMovie.y = 277;
loaderMovie.play();
Starling.juggler.add(loaderMovie);
}
public function mapLdr(){
loaderMovie.visible = true;
addChild(loaderMovie);
loaderMovie.x = 347;
loaderMovie.y = 277;
loaderMovie.play();
Starling.juggler.add(loaderMovie);
}
//this function resizes the loader to original size and places at the bottom corner
public function resizeLdr(){
loaderMovie.width = 72;
loaderMovie.height = 22;
loaderMovie.x =1237;
loaderMovie.y = 712;
}
public function callLoad(): void {
public function callHawaii(): void {
trace(" Hawaii is being runned");
//mal.mapAssets.verbose = true;
mal.mapAssets.loadQueue(function onGo(ratio: Number): void {
trace("Hawaii percentage is", ratio);
if (ratio == 1.0) {
Starling.juggler.delayCall(function (): void {
loaderMovie.visible = false;
//addChild(haw.Ocean);
// addChild(haw);
trace("this is haw value",haw);
//trace("this is the function", haw.showHawaii(null));
haw.showHawaii(null);
}, 0.30);
}
});
}
public function showMap() {
// get texture by name
addChild(mal);
mal.accesMap();
mal.hawaii.addEventListener(Event.TRIGGERED,removeMap);
}
// this code removes the HawaiiMap from the screen and goes directly to the wave
public function removeMap(){
trace("function initated");
mapLdr();
resizeLdr();
mal.mapAssets.purge();
mal.requestHawaii();
callHawaii();
mal.hawaii.removeEventListener(Event.TRIGGERED,removeMap);
}
public function Loader() {
super();
}
}
}
And here is my Asset Manager class
package Enqueue {
import flash.filesystem.File;
import Assets.MapAnimate;
import Assets.MapAssets;
import Maps.Hawaii;
import starling.animation.IAnimatable;
import starling.animation.Juggler;
import starling.animation.Transitions;
import starling.animation.Tween;
import starling.core.Starling;
import starling.core.starling_internal;
import starling.display.Button;
import starling.display.Image;
import starling.display.MovieClip;
import starling.display.Sprite;
import starling.events.EnterFrameEvent;
import starling.events.Event;
import starling.textures.Texture;
import starling.textures.TextureAtlas;
import starling.utils.AssetManager;
public class MapAssetLoadQeue extends Sprite {
public var mapAssets: AssetManager;
public function MapAssetLoadQeue() {
super();
}
public function requestHawaii():void {
// mapAssets.verbose =false;
// mapAssets = new AssetManager;
var appDir:File = File.applicationDirectory;
mapAssets.enqueue(appDir.resolvePath("IslandMaps/Hawaii"));
//mapAssets.enqueue(Hawaii);
mapAssets.verbose = true;
}
If this is all of your code, and if I'm not missing something obvious, I don't see you creating "haw" anywhere. That is, you don't appear to have anything such as...
haw = new Hawaii();
...so, it would be null!

StageVideoAvailabilityEvent not found

Im Working on Air Application and heres my Class
package
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageDisplayState;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.StageVideoAvailabilityEvent;
import flash.geom.Rectangle;
import flash.media.StageVideo;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
public class presentation extends Sprite
{
private const VIDEO_FILE_URL:String = "assets/Presentation_Demo_02.mp4";
private var video:Video;
private var stageVideo:StageVideo;
private var nc:NetConnection;
private var ns:NetStream;
private var streamClient:Object;
public function presentation()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
//stage.displayState = StageDisplayState.FULL_SCREEN;
addEventListener(Event.ADDED_TO_STAGE,init);
}
private function init(event:Event):void
{
trace("All Works");
initStream();
removeEventListener(Event.ADDED_TO_STAGE,init);
stage.addEventListener(Event.RESIZE, stageResize);
addEventListener(Event.ENTER_FRAME,update);
}
private function initStream():void
{
streamClient = new Object();
streamClient.onMetaData = onMetaData;
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.client = streamClient;
addEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY,onChange);
}
private function onChange(event:StageVideoAvailabilityEvent):void
{
trace(event.availability);
}
private function stageResize(event:Event):void
{
}
private function update(event:Event):void
{
}
public function onMetaData(e:Object):void
{}
}
}
on the line where addEventListener for StageVideoAvailabilityEvent i got Error in Flash Builder
Type was not found or was not a compile-time constant: StageVideoAvailabilityEvent.
what can i do
Be sure that you are using a version of Adobe AIR that supports StageVideo. (I recommend you to download the latest version, 17).
Update your Adobe AIR Application Description file to the respective AIR version. (in this case 17)
<application xmlns="http://ns.adobe.com/air/application/17.0">
Also, be sure that you add an extra compiler argument to indicate the respective SWF version (fro AIR 17, should be 28:
-swf-version=28

AS3 Preloader not updating screen

I've been struggling with a Flash preloader. I just want it to update the text on the screen with the current percentage. Now it basically works as the trace outputs the correct percentages, but it won't update the textfield I have on the screen. Once the trace gets to 100% however, the code does output "100" on the screen, but not until it's all loaded. I don't have the Flash IDE and am just using pure Actionscript with FlashDevelop. Here's my code:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.display.Loader;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.display.Loader;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldType;
public class Main extends Sprite
{
public var myLoader:Loader = new Loader();
public var image:String = "tmp/Avengers-poster.jpg";
private var Title:TextField;
private var txt:String;
private var Form:TextField;
public function Main():void {
textbox("This is the title","box",100,100,200,30);
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressStatus);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderReady);
var fileRequest:URLRequest = new URLRequest(image);
myLoader.load(fileRequest);
}
public function onProgressStatus(e:ProgressEvent):void {
// this is where progress will be monitored
var perc:int = Math.ceil((e.bytesLoaded/e.bytesTotal)*100);
txt = perc.toString();
Title.text = txt;
addChild (Title);
trace(perc);
}
public function onLoaderReady(e:Event):void {
// the image is now loaded, so let's add it to the display tree!
addChild(myLoader);
}
private function textbox (title_str:String,form_name:String,x:int,y:int,width:int,height:int):void {
Title = new TextField ();
Title.text = title_str;
Title.selectable = false;
Title.setTextFormat (new TextFormat ("Arial", 12, 0x777777, true));
txt = ".";
Title.x = x;
Title.y = y;
addChild (Title);
}
}
}
Thanks for your help.
Darryl
This will work. Don't recreate the TextField on each status. You only need to addChild once and update the reference to it.
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFormat;
public class Main extends Sprite
{
public var myLoader:Loader = new Loader();
public var image:String = "http://apod.nasa.gov/apod/image/0605/titan5km_huygens_big.jpg";
private var Title:TextField;
private var Form:TextField;
public function Main():void {
createTextField("This is the title","box",100,100,200,30);
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressStatus);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderReady);
var fileRequest:URLRequest = new URLRequest(image);
myLoader.load(fileRequest);
}
public function onProgressStatus(e:ProgressEvent):void {
// this is where progress will be monitored
var perc:int = Math.ceil((e.bytesLoaded/e.bytesTotal)*100);
Title.text = perc.toString();
}
public function onLoaderReady(e:Event):void {
// the image is now loaded, so let's add it to the display tree!
addChild(myLoader);
}
private function createTextField (title_str:String,form_name:String,x:int,y:int,width:int,height:int):void {
Title = new TextField();
Title.text = title_str;
Title.selectable = false;
Title.setTextFormat (new TextFormat ("Arial", 12, 0x777777, true));
Title.text = ".";
Title.x = x;
Title.y = y;
addChild (Title);
}
}
}

AS3 to get children in Gestureworks TouchSprite working

Recently just trying around with the Gestureworks multitouch.
Here I have some problem about button inside a TouchSprite, below is my code:
package
{
import com.gestureworks.core.GestureWorks;
import com.gestureworks.core.TouchSprite;
import com.gestureworks.events.GWGestureEvent;
import com.gestureworks.events.GWTouchEvent;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.Stage;
import flash.events.Event;
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.events.MouseEvent;
import flash.events.TouchEvent;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
public class Main extends GestureWorks
{
private var myDisplay:TouchSprite;
public function Main():void
{
super();
key = "xxx";
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
}
override protected function gestureworksInit():void
{
myDisplay = new TouchSprite();
myDisplay.gestureReleaseInertia = true;
myDisplay.gestureEvents = true;
myDisplay.disableNativeTransform = false;
myDisplay.disableAffineTransform = false;
myDisplay.mouseChildren = true;
myDisplay.gestureList = {"n-drag":true,"n-scale":true};
myDisplay.addChild(boliviaMap);
myDisplay.addChild(mapPink);
addChild(myDisplay);
myDisplay.addEventListener(GWGestureEvent.DRAG, gestureDragHandler);
myDisplay.addEventListener(GWGestureEvent.SWIPE, gestureSwipeHandler);
mapPink.addEventListener(TouchEvent.TOUCH_TAP, tapPink);
}
private function tapPink(e:TouchEvent):void
{
trace("PINK");
indicatorTxt.text = "PINK";
}
private function gestureDragHandler(event:GWGestureEvent):void
{
trace("g drag: ", event.value.dx, event.value.dy);
event.target.$x += event.value.dx;
event.target.$y += event.value.dy;
indicatorTxt.text = "g drag: " + event.value.dx + " " + event.value.dy;
}
}
}
apparently the myDisplay.mouseChildren = true; will make myDisplay not able to drag or scale anymore.
Before adding your bigMap button set the mouseChildren property of myDisplay to true:
myDisplay.mouseChildren = true;
This should pass mouseEvents to objects inside.
Also, depending on the effect you want (I'm assuming this is for a multi-touch screen of somesort), I'd suggest you should probably use a TouchEvent.TOUCH_TAP on bigMap instead of MouseEvent.CLICK(MouseEvents arent multi-touch and won't be responsive if there is some kind of touch on another part of the screen at the same time).
Edit:
Assuming boliviaMap and mapPink aren't TouchMovieClips or TouchSprites then do something like this:
myDisplay.graphics.beginFill(0x555555, 1);
myDisplay.graphics.drawRect(0,0,500,500);
myDisplay.graphics.endFill();
Then add your child assuming boliviaMap and mapPink are less than 500x500px:
myDisplay.addChild(boliviaMap);
myDisplay.addChild(mapPink);
Edit 2- A working example(for me anyways) combining TouchEvents with GWEvents:
package {
import flash.display.MovieClip;
import com.gestureworks.core.GestureWorks;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import com.gestureworks.core.TouchSprite;
import flash.display.Sprite;
import flash.events.TouchEvent;
public class Main extends GestureWorks {
public function Main() {
super();
key = "INSERT YOUR GW KEY HERE";
Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT;
}
override protected function gestureworksInit():void
{
trace("GestureWorks has initialized");
var myTouchSprite:TouchSprite = new TouchSprite();
myTouchSprite.graphics.beginFill(0x555555,1);
myTouchSprite.graphics.drawRect(0,0,100,100);
myTouchSprite.graphics.endFill();
myTouchSprite.gestureReleaseInertia = false;
myTouchSprite.gestureEvents = true;
myTouchSprite.disableNativeTransform = false;
myTouchSprite.disableAffineTransform = false;
myTouchSprite.gestureList = {"n-drag":true, "n-rotate":true};
myTouchSprite.mouseChildren = true;
var myTappableSprite:Sprite = new Sprite();
myTappableSprite.graphics.beginFill(0xAD3059,1);
myTappableSprite.graphics.drawRect(30,30,40,40);
myTappableSprite.graphics.endFill();
myTappableSprite.addEventListener(TouchEvent.TOUCH_TAP, tappedThis);
//myTouchSprite.addChild(myTappableSprite);
myTouchSprite.addChild(myTappableSprite);
addChild(myTouchSprite);
}
public function tappedThis(event:TouchEvent){
trace("You tapped this");
}
}
}
I should also add that this will only work on a screen/device that triggers TouchEvents(if you're clicking myTappableSprite with a mouse it won't trigger the event).

1046: Type was not found or was not a compile-time constant:Button

package
{
import flash.display.MovieClip;
import flash.display.NativeWindow;
import flash.display.NativeWindowInitOptions;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.SimpleButton;
public class PencereyiGizle extends MovieClip
{
public var natWindow:NativeWindow=new NativeWindow(
new NativeWindowInitOptions());
public var pencereyiAc_Btn:Button;
public function PencereyiGizle(fro:Button)
{
pencereAc_Btn = fro;
//Pencere ekleniyor
natWindow.width = 500;
natWindow.height = 400;
natWindow.activate();
natWindow.addEventListener(Event.CLOSING,pencereyiSakla);
pencereyiAc_Btn.label = "Pencereyi Ac";
pencereyiAc_Btn.addEventListener(MouseEvent.MOUSE_DOWN,pencereyiAktifEt);
}
//pencerenin kapanmasını engelleyip pencereyi gizliyoruz.;
private function pencereyiSakla(e:Event):void
{
e.preventDefault();
natWindow.visible = false;
}
//gizlenen pencereyi tekrar aktif hale getiriyoruz
private function pencereyiAktifEt(e:MouseEvent):void
{
natWindow.activate();
}
}
}
IN AIR;
import PencereyiGizle;
var firat:PencereyiGizle= new PencereyiGizle();
addChild(firat);
and then, i get that problem "1046: Type was not found or was not a compile-time constant:Button. "
Based on what is in your imports, I think you want to use the SimpleButton class and not the Button class. (Which is a flash component)
Either that or you are missing this import
import fl.controls.Button;
Here is an artilce from adobe on the button component.
http://www.adobe.com/devnet/flash/quickstart/button_component_as3.html