使用 TileList 作为参数调用 addChild 时,ActionScript 抛出错误 #1009

发布于 2024-10-25 14:59:32 字数 3712 浏览 3 评论 0原文

准确的说是这个错误。

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at fl.containers::BaseScrollPane/drawBackground()
    at fl.controls::TileList/draw()
    at fl.core::UIComponent/callLaterDispatcher()

现在我已经尝试了此页面中的几个 Adob​​e 自己的示例, http ://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/controls/TileList.html,它们也都抛出这个错误。

该错误是由作为 addChild 函数参数的 TileList 实例触发的。

这是我的包,当我将 displayComponent 更改为列表时,它可以正常工作。

package com.pennstate {
    import fl.data.DataProvider;
    import flash.display.MovieClip;
    import flash.display.DisplayObjectContainer;
    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.text.TextFormat;
    import flash.xml.XMLDocument;
    import com.adobe.serialization.json.JSON;
    import fl.controls.List;
    import fl.controls.TileList; 

    public class Sign {
        public var displayComponent:TileList;
        public var url:String;
        public var provider:DataProvider;
        public var mc:MovieClip;
        public var container:DisplayObjectContainer;

        public function Sign( url:String, container ) {
            this.container = container;
            this.displayComponent = new TileList();
            this.mc = new MovieClip();
            this.url = url;
            this.provider = new DataProvider();

            _componentSetup();
            loadJson();
            _componentFormat();
        }

        private function _componentSetup() {
            displayComponent.labelFunction = getLabelFieldContent;
            displayComponent.sourceFunction = getSourceFieldContent;
            displayComponent.dataProvider = provider;
            displayComponent.selectable = false;
            displayComponent.setStyle("contentPadding", 5);
            displayComponent.setSize(1720,770);
            displayComponent.move(100,200);
            displayComponent.rowHeight = 190;
            trace('End setup');
        }

        private function _componentFormat() {
            var listTextFormat:TextFormat = new TextFormat();
            listTextFormat.font = "Arial";
            listTextFormat.color = 0x000000;
            listTextFormat.bold = true;
            listTextFormat.size = 48;
            displayComponent.setRendererStyle("textFormat", listTextFormat);
            trace('End formatting');
        }

        function loadJson():void {
            var jsonLoader:URLLoader = new URLLoader();
            jsonLoader.addEventListener(Event.COMPLETE, onJsonComplete);
            jsonLoader.load( new URLRequest( url ) );
        }  

        function onJsonComplete(e:Event):void {
            trace('Loading finished.');
            var jsonData:String = e.target.data;
            trace(jsonData + "\n");
            var decodedData = JSON.decode(jsonData, false);
            for (var index in decodedData.rows) {
                provider.addItem({title: decodedData.rows[index].node.title, result: decodedData.rows[index].node.Result});
                trace(index+" => "+decodedData.rows[index].node.title);
                trace(index+" => "+decodedData.rows[index].node.Result);
            }
            container.addChild(displayComponent);
        }

        function getLabelFieldContent(item:Object):String {
            return new XMLDocument(item.title + "\n" + item.result).firstChild.nodeValue;
        }

        function getSourceFieldContent(item:Object):String {
            return item.result;
        }

    }
}

To be exact this is the error.

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at fl.containers::BaseScrollPane/drawBackground()
    at fl.controls::TileList/draw()
    at fl.core::UIComponent/callLaterDispatcher()

Now I've tried several of Adobe's own examples from this page, http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/controls/TileList.html, and they all throw this error as well.

The error is triggered by the TileList instance being the argument of the addChild function.

Here's my package, which works fine when I change the displayComponent is be a List.

package com.pennstate {
    import fl.data.DataProvider;
    import flash.display.MovieClip;
    import flash.display.DisplayObjectContainer;
    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.text.TextFormat;
    import flash.xml.XMLDocument;
    import com.adobe.serialization.json.JSON;
    import fl.controls.List;
    import fl.controls.TileList; 

    public class Sign {
        public var displayComponent:TileList;
        public var url:String;
        public var provider:DataProvider;
        public var mc:MovieClip;
        public var container:DisplayObjectContainer;

        public function Sign( url:String, container ) {
            this.container = container;
            this.displayComponent = new TileList();
            this.mc = new MovieClip();
            this.url = url;
            this.provider = new DataProvider();

            _componentSetup();
            loadJson();
            _componentFormat();
        }

        private function _componentSetup() {
            displayComponent.labelFunction = getLabelFieldContent;
            displayComponent.sourceFunction = getSourceFieldContent;
            displayComponent.dataProvider = provider;
            displayComponent.selectable = false;
            displayComponent.setStyle("contentPadding", 5);
            displayComponent.setSize(1720,770);
            displayComponent.move(100,200);
            displayComponent.rowHeight = 190;
            trace('End setup');
        }

        private function _componentFormat() {
            var listTextFormat:TextFormat = new TextFormat();
            listTextFormat.font = "Arial";
            listTextFormat.color = 0x000000;
            listTextFormat.bold = true;
            listTextFormat.size = 48;
            displayComponent.setRendererStyle("textFormat", listTextFormat);
            trace('End formatting');
        }

        function loadJson():void {
            var jsonLoader:URLLoader = new URLLoader();
            jsonLoader.addEventListener(Event.COMPLETE, onJsonComplete);
            jsonLoader.load( new URLRequest( url ) );
        }  

        function onJsonComplete(e:Event):void {
            trace('Loading finished.');
            var jsonData:String = e.target.data;
            trace(jsonData + "\n");
            var decodedData = JSON.decode(jsonData, false);
            for (var index in decodedData.rows) {
                provider.addItem({title: decodedData.rows[index].node.title, result: decodedData.rows[index].node.Result});
                trace(index+" => "+decodedData.rows[index].node.title);
                trace(index+" => "+decodedData.rows[index].node.Result);
            }
            container.addChild(displayComponent);
        }

        function getLabelFieldContent(item:Object):String {
            return new XMLDocument(item.title + "\n" + item.result).firstChild.nodeValue;
        }

        function getSourceFieldContent(item:Object):String {
            return item.result;
        }

    }
}

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

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

发布评论

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

评论(2

大姐,你呐 2024-11-01 14:59:32

您没有在构造函数中为您的 container 参数指定类型,即: UIComponent

public function Sign( url:String, container:UIComponent )

这加上它与您的成员变量同名的事实可能是原因。

You have not given your container agrument in the constructor a type i.e: UIComponent

public function Sign( url:String, container:UIComponent )

This coupled with the fact that its the same name as your member variable is probably the cause.

笑忘罢 2024-11-01 14:59:32

我必须使用 Flash CS4 GUI 将实际的 TileList 组件从组件菜单拖到舞台上才能消除此错误。

奇怪的部分是我拖到舞台上的组件不是我在代码中使用的组件。我在代码中动态创建的组件现在可以工作了。

我什至删除了添加到舞台的 TileList 组件,但它仍然有效。这对我来说听起来像是一个错误。

I had to drag an actual TileList component from the Component Menu onto the Stage using the Flash CS4 GUI to make this error go away.

The weird part is the component that I dragged onto the Stage isn't the component I use in the code. The component I created dynamically in the code now works though.

I even deleted the TileList component that I added to the Stage and it still works. This sounds like a bug to me.

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