0
votes

I have searched the web and I can't find an answer to my problem. I'm building an air app that reads txt files and displays them in the air app but for a strange reason I get 2 errors on the same line.

errors:

-1067: Implicit coercion of a value of type void to an unrelated type Function.

-1067: Implicit coercion of a value of type Class to an unrelated type flash.events:Event.

The code:

            public function init():void {
                stage.displayState =   StageDisplayState.FULL_SCREEN_INTERACTIVE;

            }

            public function txtReeks1_creationCompleteHandler():void {
                    var url:String = "Files/Reeks1.txt";
                    var loadit:URLLoader = new URLLoader();
                    loadit.addEventListener(Event.COMPLETE, completeHandler(Event));
                    loadit.load(new URLRequest(url));
            }

             public function completeHandler(event:Event):void {
                txtReeks1.text =  event.target.data;    
                stripLinesFromTextArea(txtReeks1);
            }   

             public function stripLinesFromTextArea(textArea:TextArea):void { 
                var txt:String = textArea.text; 
                var re:RegExp = /\n+/g; 
                txt = txt.replace(re,""); 
                textArea.text = txt; 
            } 
        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <mx:TabNavigator x="0" y="0" width="100%" height="100%">
        <mx:Canvas id="Reeks1" width="100%" height="100%" label="Reeks1">
            <mx:TextArea id="txtReeks1" x="0" y="0" width="100%" height="100%"
                         creationComplete="txtReeks1_creationCompleteHandler()"
                         fontFamily="Lucida Console" fontSize="20"/>
        </mx:Canvas>
        <mx:Canvas id="Reeks2" width="100%" height="100%" label="Reeks2">
        </mx:Canvas>
        <mx:Canvas id="Reeks3" width="100%" height="100%" label="Reeks3">
        </mx:Canvas>
    </mx:TabNavigator>
</mx:WindowedApplication>

I hope anybody can help me because I am searching the last 2 days for an answer

3
Which line has the errors? Can you poste the entire file? There seems to be a portion missing. - Peter Hall

3 Answers

3
votes
loadit.addEventListener(Event.COMPLETE, completeHandler(Event));

This is the problem. You are calling the handler and passing the Event class to it. When adding a listener you just have to reference the function, not call it:

loadit.addEventListener(Event.COMPLETE, completeHandler);
3
votes

The issue is in your txtReeks1_creationCompleteHandler() method on the line below:

loadit.addEventListener(Event.COMPLETE, completeHandler(Event));

The second argument should be a reference to the function, not the execution of the function itself - which returns void. So it should read as follows:

loadit.addEventListener(Event.COMPLETE, completeHandler);
0
votes

Your error is on the line :

loadit.addEventListener(Event.COMPLETE, completeHandler(Event));

You should not pass the result of the function to the event handler but the function itself:

loadit.addEventListener(Event.COMPLETE, completeHandlerEvent);