+ Reply to Thread
Results 1 to 9 of 9

Load Error for AS 3 swf

This is a discussion on Load Error for AS 3 swf within the advanced Actionscript 3.0 forums, part of the Flash English category; Hello: I have an "interface" file that uses an XML menu. Selecting the menu items loads an external SWF into ...

  1. #1
    Junior Member Settled In Pherankh is on a distinguished road
    Join Date
    Jan 2008
    Posts
    25
    Rep Power
    0

    Angry Load Error for AS 3 swf

    Hello:

    I have an "interface" file that uses an XML menu. Selecting the menu items loads an external SWF into a container movieclip on the interface stage. The SWF being loaded all have text content generated from xml too. The files that were created with AS 2 load just fine, but I started to update 2 of the files to AS 3 and when I try to load the AS 3 versions I get the following message:

    Code:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
        at roots_fla::MainTimeline/frame1()
    ("roots.swf" is the name of the loaded SWF).

    The AS 3 code is on the first frame of the main timeline of both the menu/interface and the externally loaded content. I don't really know what this error means so I wonder if anyone has had experience with this.

  2. #2
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,762
    Rep Power
    11

    Re: Load Error for AS 3 swf

    It means that Flash does not find an object you called.
    This object should stay in frame1 of roots_fla

  3. #3
    Junior Member Settled In Pherankh is on a distinguished road
    Join Date
    Jan 2008
    Posts
    25
    Rep Power
    0

    Re: Load Error for AS 3 swf

    Would that be the external XML? I really don't know what object would be "missing" after compile.

  4. #4
    Junior Member Settled In Pherankh is on a distinguished road
    Join Date
    Jan 2008
    Posts
    25
    Rep Power
    0

    Converting Timeline AS to External Classes

    I ran some tests and the menu has no problem loading SWFs that have external classes assigned to them so I think AS 3 is having a problem with the main timeline code in my loaded file. As a last step in the process I wanted to create external classes, so I guess I'll have to do that now whether I like it or not. I don't have much practice with external classes since I'm new to AS 3, so if anyone can help me with this I would appreciate it, here's the code from one of the two templates I'm using:

    Code:
    import flash.display.Stage;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.display.StageDisplayState;
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextLineMetrics;
    import flash.text.AntiAliasType;
    import flash.text.TextFormat;
    //----------------------------------------------------------------
    import flash.utils.getDefinitionByName;
    import flash.media.Sound;
    import flash.media.SoundLoaderContext;
    import flash.media.SoundChannel;
    //----------------------------------------------------------------
    
    stage.displayState = StageDisplayState.FULL_SCREEN;
    stage.scaleMode = StageScaleMode.NO_SCALE;
    
    //----------------------------------------------------------------
    content_tb.embedFonts = true;
    content_tb.selectable = false;
    
    //----------------------------------------------------------------
    var clickSound:Sound;
    var librarySoundOne:Class = getDefinitionByName ( "Click" ) as Class;
    clickSound = new librarySoundOne();
    var clickChannel:SoundChannel;
    
    //----------------------------------------------------------------
    var dingSound:Sound;
    var librarySoundTwo:Class = getDefinitionByName ( "Ding" ) as Class;
    dingSound = new librarySoundTwo();
    var dingChannel:SoundChannel;
    
    //----------------------------------------------------------------
    var xmlLoader:URLLoader = new URLLoader();
    var xmlData:XML = new XML();
    xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
    xmlLoader.load(new URLRequest("xml/modernism.xml"));
    function LoadXML(e:Event):void {
        xmlData = new XML(e.target.data);
        LoadContent(xmlData);
    }
    //----------------------------------------------------------------
    function LoadContent(textData:XML):void {
        //CONTENT TO BE DISPLAYED ON INITIAL LOAD
        var defaultText = textData.item[0].content.text();
        var pageTitle_text = textData.item.label.text()[0];
        pageTitle_tb.htmlText = "<b>" + pageTitle_text + "</b>";
        var formatSpacing:TextFormat = new TextFormat();
        formatSpacing.letterSpacing = 4;
        pageTitle_tb.setTextFormat(formatSpacing);
        //----------------------------------------
        function setPage(page:Number):void {
            field.scrollV = (page - 1) * linesPerPage + 1;
        }
        // Assigns the text field that is on the stage to a local variable
        var field:TextField = content_tb;
        field.embedFonts = true;
        // Assign the content to the text field
        field.htmlText = defaultText;
    
        // Extracts the text format and line height properties
        var format:TextFormat = field.getTextFormat();
    
        var leading = int(format.leading);
        var extent:TextLineMetrics = field.getLineMetrics(0);
        var ascent = extent.ascent;
        var descent = extent.descent;
    
        // CALCULATE lineHeight  VALUE USING A SINGLE FONT SIZE
        // IF HTML TEXT INCLUDES HEADINGS OF DIFFERING SIZES THE NUMBERS 
        // WILL BE SKEWED. ONCE lineHeight IS CALCULATED YOU CAN HARDCODE
        // THE VALUE BELOW AND THEN GO BACK AND RESTORE HTML FONT SIZES
        //var lineHeight = ascent + descent + leading;
        var lineHeight = 16;
        var linesPerPage = Math.floor((field.height - 4 + leading) / lineHeight);
        //field.numLines
        var lineCount = (field.maxScrollV - 1) + linesPerPage;
        var pageCount = Math.ceil(lineCount / linesPerPage);
    
        var offset = (linesPerPage * pageCount) - lineCount + 1;
        var lineBreak:String = "<br />";
        //var lineBreak:String = "\r\n";
    
        for (var i = 0; i < offset; i++) {
            defaultText.htmlText += lineBreak;
        }
        //LINE BELOW IS A NECESSARY REPEAT
        field.htmlText = defaultText;
    
        var panelNum = pageCount;
        var curNum = 1;
        pageNum.htmlText = "<b>" + curNum + "</b>";
        pageTotal.htmlText = "<b>" + panelNum + "</b>";
        prevButton_mc.visible = false;
    
        function NextOnClick(event:MouseEvent):void {
            curNum++;
            pageNum.htmlText = "<b>" + curNum + "</b>";
            setPage(curNum);
            if (curNum == 2) {
                prevButton_mc.visible = true;
                clickChannel = clickSound.play();
            } else if (curNum == panelNum) {
                event.currentTarget.visible = false;
                curNum = panelNum;
                dingChannel = dingSound.play();
            } else {
                clickChannel = clickSound.play();
            }
    
        }
        nextButton_mc.buttonMode = true;
        nextButton_mc.addEventListener(MouseEvent.CLICK, NextOnClick);
    
        function PrevOnClick(event:MouseEvent):void {
            curNum--;
            pageNum.htmlText = "<b>" + curNum + "</b>";
            setPage(curNum);
            if (curNum == 1) {
                setPage(curNum);
                event.currentTarget.visible = false;
                curNum = 1;
                dingChannel = dingSound.play();
            } else {
                clickChannel = clickSound.play();
            }
            nextButton_mc.visible = true;
        }
        prevButton_mc.buttonMode = true;
        prevButton_mc.addEventListener(MouseEvent.CLICK, PrevOnClick);
    }
    The code is my upgrade of an old AS 2 pagination technique - lets you divide a block of xml into individual pages to navigate through. I'm shocked to say that I actually have this working.

  5. #5
    Junior Member Settled In Pherankh is on a distinguished road
    Join Date
    Jan 2008
    Posts
    25
    Rep Power
    0

    Question Re: Load Error for AS 3 swf

    I have been trying to convert the code posted previously to a custom class:

    Code:
    package {
        import flash.display.*;
        import flash.events.*;
        import flash.net.*;
        import flash.display.Stage;
        import flash.display.StageAlign;
        import flash.display.StageScaleMode;
        import flash.events.Event;
        import flash.display.StageDisplayState;
        import flash.accessibility.AccessibilityProperties;
        import flash.display.Sprite;
        import flash.text.TextField;
        import flash.text.TextLineMetrics;
        import flash.text.AntiAliasType;
        import flash.text.TextFormat;
        //----------------------------------------------------------------
        import flash.utils.getDefinitionByName;
        import flash.media.Sound;
        import flash.media.SoundLoaderContext;
        import flash.media.SoundChannel;
        //----------------------------------------------------------------
        var stage:Stage;
        var content_tb:TextField;
        var xmlLoader:URLLoader;
        //----------------------------------------------------------------
        stage.displayState = StageDisplayState.FULL_SCREEN;
        stage.scaleMode = StageScaleMode.NO_SCALE;
        //----------------------------------------------------------------
        content_tb.embedFonts = true;
        content_tb.selectable = false;
        //----------------------------------------------------------------
        var clickSound:Sound;
        var librarySoundOne:Class = getDefinitionByName ( "Click" ) as Class;
        clickSound = new librarySoundOne();
        var clickChannel:SoundChannel;
        //----------------------------------------------------------------
        var dingSound:Sound;
        var librarySoundTwo:Class = getDefinitionByName ( "Ding" ) as Class;
        dingSound = new librarySoundTwo();
        var dingChannel:SoundChannel;
        //----------------------------------------------------------------
    
        // Demonstrates the code required to load external XML
        public class LoadXML extends MovieClip {
            var xmlLoader:URLLoader = new URLLoader();
            var xmlData:XML = new XML();
            xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
            xmlLoader.load(new URLRequest("xml/modernism.xml"));
    
            // Constructor
            public function LoadXML(e:Event):void {
                xmlData = new XML(e.target.data);
                LoadContent(xmlData);
            }
            // Method invoked automatically when the XML finishes loading
            function LoadContent(textData:XML):void {
                //CONTENT TO BE DISPLAYED ON INITIAL LOAD
                var defaultText = textData.item[0].content.text();
                var pageTitle_text = textData.item.label.text()[0];
                pageTitle_tb.htmlText = "<b>" + pageTitle_text + "</b>";
                var formatSpacing:TextFormat = new TextFormat();
                formatSpacing.letterSpacing = 4;
                pageTitle_tb.setTextFormat(formatSpacing);
    
                //----------------------------------------
    
                function setPage(page:Number):void {
                    field.scrollV = (page - 1) * linesPerPage + 1;
                }
                // Assigns the text field that is on the stage to a local variable
                var field:TextField = content_tb;
                field.embedFonts = true;
                // Assign the content to the text field
                field.htmlText = defaultText;
    
                // Extracts the text format and line height properties
                var format:TextFormat = field.getTextFormat();
    
                var leading = int(format.leading);
                var extent:TextLineMetrics = field.getLineMetrics(0);
                var ascent = extent.ascent;
                var descent = extent.descent;
    
                // CALCULATE THIS NUMBER USING BODY TEXT OF THE SAME FONT SIZE
                // IF HTML TEXT INCLUDES HEADINGS OF DIFFERING SIZES THE NUMBERS WILL BE SKEWED
                //var lineHeight = ascent + descent + leading;
                var lineHeight = 16;
                var linesPerPage = Math.floor((field.height - 4 + leading) / lineHeight);
                var lineCount = (field.maxScrollV - 1) + linesPerPage;
                var pageCount = Math.ceil(lineCount / linesPerPage);
    
                var offset = (linesPerPage * pageCount) - lineCount + 1;
                var lineBreak:String = "<br />";
                //var lineBreak:String = "\r\n";
    
                for (var i = 0; i < offset; i++) {
                    defaultText.htmlText += lineBreak;
                }
                //LINE BELOW IS A NECESSARY REPEAT
                field.htmlText = defaultText;
    
                var panelNum = pageCount;
                var curNum = 1;
                pageNum.htmlText = "<b>" + curNum + "</b>";
                pageTotal.htmlText = "<b>" + panelNum + "</b>";
                prevButton_mc.visible = false;
    
                function NextOnClick(event:MouseEvent):void {
                    curNum++;
                    pageNum.htmlText = "<b>" + curNum + "</b>";
                    setPage(curNum);
                    if (curNum == 2) {
                        prevButton_mc.visible = true;
                        clickChannel = clickSound.play();
                    } else if (curNum == panelNum) {
                        event.currentTarget.visible = false;
                        curNum = panelNum;
                        dingChannel = dingSound.play();
                    } else {
                        clickChannel = clickSound.play();
                    }
    
                }
                nextButton_mc.buttonMode = true;
                nextButton_mc.addEventListener(MouseEvent.CLICK, NextOnClick);
    
                function PrevOnClick(event:MouseEvent):void {
                    curNum--;
                    pageNum.htmlText = "<b>" + curNum + "</b>";
                    setPage(curNum);
                    if (curNum == 1) {
                        setPage(curNum);
                        event.currentTarget.visible = false;
                        curNum = 1;
                        dingChannel = dingSound.play();
                    } else {
                        clickChannel = clickSound.play();
                    }
                    nextButton_mc.visible = true;
                }
                prevButton_mc.buttonMode = true;
                prevButton_mc.addEventListener(MouseEvent.CLICK, PrevOnClick);
            }
        }
    }
    I've managed to eliminate all the errors except one:
    Code:
    1067: Implicit coercion of a value of type Class to an unrelated type Function.
    . That error refers to the following line:
    Code:
    xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
    The compiler doesn't like the name of the public function I guess. Shouldn't the public function name be the same as it's class name?

  6. #6
    Junior Member Settled In Pherankh is on a distinguished road
    Join Date
    Jan 2008
    Posts
    25
    Rep Power
    0

    Custom class from main timeline code

    I know this has to be implemented in stages, so here are some files to play with - Can anyone get the XML to display in the textfield ("content_tb") on stage?

    http://www.tornedgedesign.com/_test/...stom_class.zip

    Note: the code worked originally when it was on the main timeline, but I need to translate it into classes.

  7. #7
    Junior Member Settled In al2.0 is on a distinguished road
    Join Date
    Apr 2008
    Posts
    2
    Rep Power
    0

    Re: Load Error for AS 3 swf

    Hi I'm al2.0 1067: Implicit coercion of a value of type Function to an unrelated type flash.media:SoundChannel.
    var myChannel:SoundChannel=mySound.play;
    What does mean? and how can i fix the problem

  8. #8
    CSS.FlepStudio.org Moving My Stuff To The FlepStudio Onsitus is on a distinguished road Onsitus's Avatar
    Join Date
    Jul 2007
    Posts
    1,436
    Rep Power
    7

    Re: Load Error for AS 3 swf

    var myChannel:SoundChannel=mySound.play();

  9. #9
    Junior Member Settled In al2.0 is on a distinguished road
    Join Date
    Apr 2008
    Posts
    2
    Rep Power
    0

    Re: Load Error for AS 3 swf

    Thanks Onsitus

+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 27-04-09, 18:52
  2. Load external *swf - error #1009
    By Marshall157 in forum advanced Actionscript 3.0
    Replies: 1
    Last Post: 06-04-09, 14:18
  3. Error 1009 Load XML
    By loris.dassie in forum Actionscript 3.0 base
    Replies: 0
    Last Post: 10-07-08, 14:20
  4. Load external *swf - error #1009
    By Vinnie in forum Actionscript 3.0 newbies
    Replies: 7
    Last Post: 04-06-08, 13:48
  5. Error upon load - need help ASAP
    By Zombie in forum Actionscript 3.0 newbies
    Replies: 5
    Last Post: 30-03-08, 04:17

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts