It means that Flash does not find an object you called.
This object should stay in frame1 of roots_fla
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 ...
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:
("roots.swf" is the name of the loaded SWF).Code:TypeError: Error #1009: Cannot access a property or method of a null object reference. at roots_fla::MainTimeline/frame1()
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.
It means that Flash does not find an object you called.
This object should stay in frame1 of roots_fla
Would that be the external XML? I really don't know what object would be "missing" after compile.
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:
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.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); }
I have been trying to convert the code posted previously to a custom class:
I've managed to eliminate all the errors except one: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); } } }. That error refers to the following line:Code:1067: Implicit coercion of a value of type Class to an unrelated type Function.
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?Code:xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
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.
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
var myChannel:SoundChannel=mySound.play();
![]()
CSS.FlepStudio.org in english: css tutorials, free css template and css menu
Conversione da PSD a XHTML/CSS - Creazione siti web - Introduzione CSS3
Thanks Onsitus
Bookmarks