【问题标题】:Error #1009: Cannot access a property or method of a null object ref AS3 project错误 #1009:无法访问空对象引用 AS3 项目的属性或方法
【发布时间】:2019-12-08 08:05:11
【问题描述】:

我有一个 AS3 项目,我试图创建一种显示 GIF 或 SWF(从 gi​​f 在线转换)的方法,就像显示单个图像一样。

单个图像与类一起显示,然后在 Main.as 中引用。同样对于 gif 或 swf,我扩展了 MovieClip:

(是的,我阅读了其他主题并没有帮助)

package com.mee.mytest
{
    import flash.display.Bitmap;
    import flash.events.Event;  
    import flash.display.MovieClip; 

    /**
     * ...
     * @author Mee
     */

    public class MyTest extends MovieClip
    {
        [Embed(source="../../../../assets/spfx_MyClip.swf", mimeType="application/octet-stream")]
        private static const cMyTest : Class;
        private var swfMyClip : MovieClip;

        public function MyTest() 
        {
            swfMyClip = new cMyTest() as MovieClip;
            swfMyClip.scaleX = 600;
            swfMyClip.scaleY = 400;
            addChild(swfMyClip);

        }

    }

}

现在是我的主要内容:

import com.mee.mytest.MyTest
    import flash.desktop.NativeApplication;
    import flash.display.Bitmap;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;

public class Main extends Sprite 
    {
        public var vMyTest : MyTest; //this is var = the class

        public function Main() 
        {
            stage.align = StageAlign.TOP_LEFT;
            stage.addEventListener(Event.DEACTIVATE, deactivate);
            stage.scaleMode = StageScaleMode.NO_SCALE;          
            stage.setAspectRatio(StageAspectRatio.LANDSCAPE);           

            // touch or gesture? BLAH BLAH
            Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

            testMyGif();
        }

        function testmyGif():void
        {

            vMyTest = new MyTest();
            addChild(vMyTest);

        }

错误错误错误

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at com.mee.mytest::MyTest()
    at Main/testmyGif()
    at Main()

【问题讨论】:

  • 您不会像以前那样将其他 SWF 嵌入到您的应用程序中。这意味着, cMyTest 不是一个有效的 DisplayObject 类(我认为嵌入这样的文件会产生一个 ByteArray 类),这会导致 new cMyTest() as MovieClip 生成 null 引用而不是 MovieClip 实例。因此,错误。

标签: actionscript-3 flash actionscript gif


【解决方案1】:

dem ...只是为了any1的缘故。它主要来自'您显示的 SWF 应该与构建的 swf 在同一个文件夹中,然后 url 有新的 URLRequest("myfile.swf") 忘记其他文件夹或 ..exiting 文件夹,这是避免的唯一方法任何其他 URL 错误

使用

public var loader : Loader = new Loader();
public var urlRequ : URLRequest = new URLRequest("MyFile.swf")  

    loader.load(urlRequ);
    addChild(loader);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多