Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-03-2008, 08:42 PM   #1
basement
Registered User
 
Join Date: Nov 2008
Posts: 3
Default Error #2007: Parameter text must be non-null

I'm using a code to random show a quote and works fine however I'm getting an error:

TypeError: Error #2007: Parameter text must be non-null.
at flash.text::TextField/set text()
at quotes_fla::MainTimeline/rotateQuote()
at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
at flash.utils::Timer/flash.utils:Timer::tick()

The code I'm using is:
ActionScript Code:
import caurina.transitions.Tweener; var quote:Array = new Array(); var totalQuotes:Number; quoteMC.alpha = 0; var rotateTimer:Timer = new Timer(5000, 100);//rotates the quote every 2 seconds for 100 times rotateTimer.addEventListener("timer", rotateQuote);//add a listener to the timer rotateTimer.start();// start the timer function init():void {     var quotesXML:XML = new XML();     quotesXML.ignoreWhitespace = true;     var XMLURL:URLRequest = new URLRequest("flash/quotes1.xml");     var myLoader:URLLoader = new URLLoader(XMLURL);     myLoader.addEventListener("complete", xmlLoaded);     function xmlLoaded(event:Event):void {         quotesXML = XML(myLoader.data);         totalQuotes = quotesXML.quote.length();         for (var i:int = 0; i < quotesXML.quote.length(); i++) {             quote[i] = quotesXML.quote[i].text;         }         var initRandom:Number = randomNumber(0, totalQuotes);         Tweener.addTween(quoteMC, {alpha:1, time:5});         quoteMC.quote_txt.text = String(quote[initRandom]);     }     } function rotateQuote(evt:TimerEvent) {     quoteMC.alpha = 0;     Tweener.addTween(quoteMC, {alpha:1, time:5});     quoteMC.quote_txt.text = "";     var randomness:Number = randomNumber(0, totalQuotes);     quoteMC.quote_txt.text = quote[randomness]; } function randomNumber(low:Number, high:Number):Number {     var low:Number = low;     var high:Number = high;     return Math.round(Math.random() * high - low) + low; } init();

I couldn't find a similar code to understand why it's wrong.
I'm totally new at as3 so any help will be welcome.
Thanks in advance.

BTW, the error only shows at IE, in Firefox it seems ok.
basement is offline   Reply With Quote
Old 11-04-2008, 02:14 PM   #2
basement
Registered User
 
Join Date: Nov 2008
Posts: 3
Default

If there is anybody trying to help, the original code is from Tiago's Blog: http://blog.six4rty.ch/tutorials/fla...quote-rotator/

And when I debugged it, the error pops up at line 35:

quoteMC.quote_txt.text = quote[randomness];

thanks
basement is offline   Reply With Quote
Old 11-04-2008, 03:27 PM   #3
creynders
flash veteran
 
creynders's Avatar
 
Join Date: May 2005
Location: Belgium
Posts: 914
Default

The Timer object immediately sends a "timer" event, which means that it's listener ("rotateQuote") is executed before the XML has finished loading.
In this case the function "randomNumber" returns a number between 0 and 0
so, the error-throwing line is translated to:
quoteMC.quote_txt.text = quote[0];
but since the XML hasn't loaded yet "quote" is empty so it returns "null"
thet "text" property of the TextField doesn't accept "null" as a value, hence the error
creynders is offline   Reply With Quote
Old 11-04-2008, 04:54 PM   #4
basement
Registered User
 
Join Date: Nov 2008
Posts: 3
Default

Great explanation creynders, even for me that I'm new at this.

I didn't though this could be the problem because it was actually working. Thinking about it: the error pops up at random, so maybe it was that when the "rotate" and "Tweener" sync at a specific interval, just then the error appear??

Anyway, in another forum they suggest me the following trick:

quoteMC.quote_txt.text = quote[randomness]||"";

And it actually worked.

Thanks.
basement is offline   Reply With Quote
Old 11-05-2008, 07:46 AM   #5
creynders
flash veteran
 
creynders's Avatar
 
Join Date: May 2005
Location: Belgium
Posts: 914
Default

It worked, because it's a solution for the problem I described.

What you're writing there is a conditional assignment it means (roughly translated) if quote[randomness] translates to nothing then take the value "" (which is just an empty string)

The reason why it seems to randomly popup is because sometimes the xml will have loaded before the function is executed and sometimes not.
creynders is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
User editable text for Star wars effect tomtomA920Dude ActionScript 2.0 4 12-10-2008 11:05 PM
Big Challenge tombot18 Simple Stuff (Newbies) 11 10-28-2007 11:54 PM
How do you something like this ... newttyy HTML and JavaScript 1 10-15-2007 09:02 PM
calling a PDF file in Flash AudryLucy Projectors and CDs 20 12-30-2006 01:43 PM
cells in scrollable text window? oldspice ActionScript 1.0 (and below) 2 04-02-2002 02:59 PM


All times are GMT. The time now is 04:22 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.