从文档类中的方法定位精灵 - 空对象引用

发布于 2024-10-16 14:12:50 字数 1805 浏览 3 评论 0原文

我正在尝试完全在文档类中编写 Flash 应用程序。我正在使用带触摸屏的 GestureWorks。当用户按下按钮时,它会调用一个方法,该方法应该隐藏特定的图形,但不隐藏他们触摸的图形。

本质上,我需要一种使用“e.target”之外的方法来引用屏幕上的图形的方法。

我收到此错误:错误 #1009:无法访问空对象引用的属性或方法。

            //This code works 
            private function photo1SpriteFlickHandler(e:GestureEvent):void {
                    var openTween:Tween = new Tween(e.target, "x", Strong.easeOut, 232, 970, 5, true);
            }

            //this code gives me a null object reference 

            private function photo1SpriteFlickHandler(e:GestureEvent):void {
                    var openTween:Tween = new Tween(photo1Sprite, "x", Strong.easeOut, 232, 970, 5, true);
            }

            //photo1Sprite has already been programatically added to the screen as so:
            var photo1Sprite = new TouchSprite();
                    var photo1Loader=new Loader();
                    photo1Loader.load(new URLRequest("media/photos1/photo1.jpg"));
                    photo1Loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderComplete);

                    photo1Sprite.x = 232;
                    photo1Sprite.y = 538;
                    photo1Sprite.scaleX = .3;
                    photo1Sprite.scaleY = .3;
                    photo1Sprite.blobContainerEnabled = true;
                    photo1Sprite.addEventListener(TouchEvent.TOUCH_DOWN, startDrag_Press);
                    photo1Sprite.addEventListener(TouchEvent.TOUCH_UP, stopDrag_Release);

                    photo1Sprite.addChild(photo1Loader);

                addChild(photo1Sprite);

当按钮单击发生在 photo1Sprite 上时,它可以将 photo1Sprite 作为“e.target”访问。

当单击一个按钮(不是 photo1Sprite)并使其影响 photo1Sprite 时,就会出现问题。

因此,如果我的方法使用“e.target”直接附加到它,我可以使 photo1Sprite 做出反应,但如果我尝试从屏幕上另一个元素调用的方法调用它,则不能。

I am trying to code a flash app entirely in the document class. I am using GestureWorks with a touch screen. When a user essentially presses a button it calls a method that should hide a specific graphic but not the graphic they touched.

Essentially I need a way to refer to a graphic on the screen using a method besides 'e.target'.

I am receiving this error: Error #1009: Cannot access a property or method of a null object reference.

            //This code works 
            private function photo1SpriteFlickHandler(e:GestureEvent):void {
                    var openTween:Tween = new Tween(e.target, "x", Strong.easeOut, 232, 970, 5, true);
            }

            //this code gives me a null object reference 

            private function photo1SpriteFlickHandler(e:GestureEvent):void {
                    var openTween:Tween = new Tween(photo1Sprite, "x", Strong.easeOut, 232, 970, 5, true);
            }

            //photo1Sprite has already been programatically added to the screen as so:
            var photo1Sprite = new TouchSprite();
                    var photo1Loader=new Loader();
                    photo1Loader.load(new URLRequest("media/photos1/photo1.jpg"));
                    photo1Loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderComplete);

                    photo1Sprite.x = 232;
                    photo1Sprite.y = 538;
                    photo1Sprite.scaleX = .3;
                    photo1Sprite.scaleY = .3;
                    photo1Sprite.blobContainerEnabled = true;
                    photo1Sprite.addEventListener(TouchEvent.TOUCH_DOWN, startDrag_Press);
                    photo1Sprite.addEventListener(TouchEvent.TOUCH_UP, stopDrag_Release);

                    photo1Sprite.addChild(photo1Loader);

                addChild(photo1Sprite);

It can access photo1Sprite as 'e.target' when the button click happens on the photo1Sprite.

The problem happens when to click one button (not photo1Sprite) and have it effect photo1Sprite.

So I can make photo1Sprite react if my method is attached to it directly using 'e.target' but not if I am trying to call it from a method that was called from another element on the screen.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天涯离梦残月幽梦 2024-10-23 14:12:50

我不确定 Tween 类构造函数期望什么作为第一个参数。它是一个 Sprite 实例还是 Sprite 实例的名称?无论如何,请确保 - 在 photo1SpriteFlickHandler 的上下文中 - photo1Sprite 已 1) 定义! 2) 指的是正确的事物。

I'm not sure what the Tween class constructor expects as it first argument. Is it a Sprite instance or is it the name of a Sprite instance? In any case make sure that - in the context of photo1SpriteFlickHandler - photo1Sprite is 1) defined! and 2) refers to the correct thing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文