使用GPS.ane开发应用遇1120错误:未定义属性onClickStop求助
1120: Access of undefined property onClickStop Error with GPS.ane Hey there! Let’s work through this error you’re stuck on—1120: Access of undefined property onClickStop is a super common ActionScript issue, and it usually boils down to the compiler not being able to find the method you’re referencing. Since you’re building an app to grab GPS coordinates with the GPS.ane component, here are the most likely fixes to get you back on track:
1. Double-Check Your Method Definition
First, make sure the onClickStop method actually exists in your code, and it’s accessible to the part of your app that’s calling it:
- Spelling & Case: ActionScript is case-sensitive—don’t mix up uppercase/lowercase (e.g.,
onclickstoporOnClickStopwon’t work). - Access Modifier: If you’re calling this method from MXML (like a button’s
clickevent) or an external class, the method needs to be markedpublic. Example:public function onClickStop(event:MouseEvent):void { // Add your logic to stop GPS updates here gpsManager.stopUpdating(); // Replace with your actual GPS.ane stop method } - No Nested Functions: Don’t define
onClickStopinside another function—keep it as a top-level method in your class so the compiler can find it.
2. Verify Event Binding
If you’re triggering onClickStop via a UI element (like a stop button), confirm the binding is set up correctly:
- MXML Binding: If you’re using MXML, make sure the
clickevent points to the exact method name, and the method lives in the same script block or document class:<s:Button label="Stop GPS" click="onClickStop(event)"/> - ActionScript Listener: If you’re adding the listener dynamically, double-check the method reference in your
addEventListenercall:stopGPSButton.addEventListener(MouseEvent.CLICK, onClickStop);
3. Clear Compiler Cache
Sometimes your IDE (like Flash Builder) holds onto old cached code, even after you’ve added the method. Try:
- Cleaning your project (go to
Project > Clean...in Flash Builder) - Rebuilding the project from scratch
4. Confirm GPS.ane Integration (Indirect Check)
While this error is about an undefined method, incomplete ANE setup can sometimes cause weird side effects. Quick checks:
- Ensure the GPS.ane is properly added to your project’s build path
- Verify your
app.xmlfile includes the correct ANE extension ID and required permissions (like location access for Android/iOS)
Example Working Snippet
Here’s a quick snippet to show how everything should tie together for a basic GPS stop button:
package com.yourapp { import flash.events.MouseEvent; import flash.display.Sprite; import com.yourgps.GPSManager; // Adjust to match your GPS.ane's manager class public class LocationTracker extends Sprite { private var gpsManager:GPSManager; public function LocationTracker() { initGPS(); setupStopButton(); } private function initGPS():void { gpsManager = new GPSManager(); gpsManager.startUpdating(); // Start grabbing location data } private function setupStopButton():void { var stopBtn:Sprite = new Sprite(); // Add button visuals here (or use a standard UI component) stopBtn.addEventListener(MouseEvent.CLICK, onClickStop); addChild(stopBtn); } // Public method accessible to the event listener public function onClickStop(event:MouseEvent):void { gpsManager.stopUpdating(); trace("GPS tracking stopped successfully"); } } }
If you’re still stuck, sharing the code around line 55 (where the error occurs) would help narrow things down even more!
内容的提问来源于stack exchange,提问作者Travis Huff

