开发者

ActionScript throwing Error #1009 when calling addChild with a TileList as the argument

开发者 https://www.devze.com 2023-02-19 00:40 出处:网络
To be exact this is the error. TypeError: Error #1009: Cannot access a property or method of a null object reference.

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 Tile开发者_C百科List();
            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;
        }

    }
}


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号