**试图为我的应用程序使用GPS.ane并且我一直收到错误
“第55行,第50列1120:访问未定义的属性onClickStop。”
这是令我头疼的线路我认为我错过了一些小但我无法找到它。您会认为该应用程序会给出您所在位置的纬度和经度。谢谢你的帮助**
** package {
import com.myflashlab.air.extensions.gps.Gps;
import com.myflashlab.air.extensions.gps.LocationAccuracy;
import com.myflashlab.air.extensions.gps.Location;
import com.myflashlab.air.extensions.gps.GpsEvent;
import com.myflashlab.air.extensions.nativePermissions.PermissionCheck;
import flash.utils.setTimeout;
import com.myflashlab.air.extensions.dependency.OverrideAir;
import flash.desktop.NativeApplication;
import flash.desktop.SystemIdleMode;
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.StatusEvent;
import flash.events.InvokeEvent;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.events.TouchEvent;
import flash.filesystem.File;
import flash.text.AntiAliasType;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.ui.Keyboard;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
public class Main extends MovieClip{
private var _exPermissions:PermissionCheck = new PermissionCheck();
public function Main() {
// constructor code
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate);
NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate);
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvoke);
NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys);
stage.scaleMode = StageScaleMode.EXACT_FIT;
stage.align = StageAlign.TOP_LEFT;
startBtn.addEventListener(TouchEvent.TOUCH_TAP, onClickStart);
stopBtn.addEventListener(TouchEvent.TOUCH_TAP, onClickStop);
checkPermissions();
}
private function onInvoke(e:InvokeEvent):void
{
NativeApplication.nativeApplication.removeEventListener(InvokeEvent.INVOKE, onInvoke);
}
private function handleActivate(e:Event):void
{
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
}
private function handleDeactivate(e:Event):void
{
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.NORMAL;
}
private function handleKeys(e:KeyboardEvent):void
{
if(e.keyCode == Keyboard.BACK)
{
e.preventDefault();
NativeApplication.nativeApplication.exit();
}
}
private function checkPermissions():void
{
// first you need to make sure you have access to the Location API
var permissionState:int;
if(_exPermissions.os == PermissionCheck.ANDROID)
{
permissionState = _exPermissions.check(PermissionCheck.SOURCE_LOCATION);
}
else if(_exPermissions.os == PermissionCheck.IOS)
{
permissionState = _exPermissions.check(PermissionCheck.SOURCE_LOCATION_WHEN_IN_USE);
}
if (permissionState == PermissionCheck.PERMISSION_UNKNOWN || permissionState == PermissionCheck.PERMISSION_DENIED)
{
if(_exPermissions.os == PermissionCheck.ANDROID)
{
_exPermissions.request(PermissionCheck.SOURCE_LOCATION, onRequestResult);
}
else if(_exPermissions.os == PermissionCheck.IOS)
{
_exPermissions.request(PermissionCheck.SOURCE_LOCATION_WHEN_IN_USE, onRequestResult);
}
}
else
{
textDisplay.appendText("permissions are already ok, you can use gps features."+ "\n");
init();
}
function onRequestResult($state:int):void
{
if ($state != PermissionCheck.PERMISSION_GRANTED)
{
textDisplay.appendText("You did not allow the app the required permissions!"+ "\n");
}
else
{
textDisplay.appendText("necessary permissions are now granted."+ "\n");
init();
}
}
}
public function onClickStart (evt:TouchEvent):void{
textDisplay.appendText("Location Uptade Started.\n");
// use the start method to get gps information periodically (the gps icon will be shown at your device status bar)
Gps.location.addEventListener(GpsEvent.LOCATION_UPDATE, onLocationUpdate);
Gps.location.start(LocationAccuracy.HIGH, 0, 5000);
startBtn.alpha = 0.5;
stopBtn.alpha = 1;
}
public function onClickstop (evt:TouchEvent):void{
textDisplay.appendText("Location Uptade Stopped.\n");
// simply stop the gps service when you don't need to get location information periodically anymore.
Gps.location.removeEventListener(GpsEvent.LOCATION_UPDATE, onLocationUpdate);
Gps.location.stop();
startBtn.alpha = 1;
stopBtn.alpha = 0.5;
}
function onLocationUpdate(e:GpsEvent):void
{
textDisplay.appendText(" ------------------------------- onLocationUpdate"+ "\n");
var loc:Location = e.param;
textDisplay.appendText("accuracy = " + loc.accuracy+ "\n");
textDisplay.appendText("altitude = " + loc.altitude+ "\n");
textDisplay.appendText("bearing = " + loc.bearing+ "\n");
textDisplay.appendText("latitude = " + loc.latitude+ "\n");
textDisplay.appendText("longitude = " + loc.longitude+ "\n");
textDisplay.appendText("provider = " + loc.provider+ "\n");
textDisplay.appendText("speed = " + loc.speed+ "\n");
textDisplay.appendText("time = " + loc.time+ "\n");
textDisplay.appendText("---------------------------------"+ "\n");
}
private function myDebuggerDelegate($ane:String, $class:String, $msg:String):void
{
textDisplay.appendText($ane+"("+$class+") "+$msg+ "\n");
}
private function init():void
{
// remove this line in production build or pass null as the delegate
OverrideAir.enableDebugger(myDebuggerDelegate);
Gps.init(); // call init only once in your project
// will return null if no known last location has been found
Gps.location.getLastLocation(onLocationResult);
// may take a while depending on when gps info is found
Gps.location.getCurrentLocation(onLocationResult);
function onLocationResult($result:Location):void
{
if (!$result)
{
textDisplay.appendText("location is null"+ "\n");
return;
}
textDisplay.appendText("accuracy = " + $result.accuracy+ "\n");
textDisplay.appendText("altitude = " + $result.altitude+ "\n");
textDisplay.appendText("bearing = " + $result.bearing+ "\n");
textDisplay.appendText("latitude = " + $result.latitude+ "\n");
textDisplay.appendText("longitude = " + $result.longitude+ "\n");
textDisplay.appendText("provider = " + $result.provider+ "\n");
textDisplay.appendText("speed = " + $result.speed+ "\n");
textDisplay.appendText("time = " + $result.time+ "\n");
textDisplay.appendText("---------------------------------"+ "\n");
}
}
}
} **
答案 0 :(得分:0)
stopBtn.addEventListener(TouchEvent.TOUCH_TAP,onClickStop);
公共函数onClickstop(evt:TouchEvent):void {
您的功能在停止时具有较低的大小写,但是当您引用它时,您使用大写S.
认为这一切都是错误的