#2007: Parameter listener must be non-null. YOU WHAT?
TypeError: Error #2007: Parameter listener must be non-null.
at flash.events::EventDispatcher/addEventListener()
at as3_testsite_fla::MainTimeline/setSelectedBtn()
at as3_testsite_fla::MainTimeline/doClick()
Hey guys, wondering if someone has a very simple answer to this. I bet its that i have just been stupid and forgotten to add something but can think. i had a search around but cannot find exactly what i am looking for.
Below is a copy of the button array script. I have commented where the error is occuring (MOTION_FINISH)
Actionscript Code:
var buttonsArray:Array = [themenu.aboutus_btn,themenu.portfolio_btn,themenu.contact_btn,homebtn]; function setButtons():void { for(var i:int=0; i<buttonsArray.length; i++) { buttonsArray[i].id = i; buttonsArray[i].buttonMode = true; buttonsArray[i].mouseChildren = false; buttonsArray[i].mouseEnabled = true; buttonsArray[i].addEventListener(MouseEvent.ROLL_OVER,playOver); buttonsArray[i].addEventListener(MouseEvent.ROLL_OUT,playOut); buttonsArray[i].addEventListener(MouseEvent.CLICK,doClick); } } function playOver(event:MouseEvent):void { event.currentTarget.gotoAndPlay("over"); } function playOut(event:MouseEvent):void { event.currentTarget.gotoAndPlay("out"); }
//////////THIS LITTLE RASCAL IS CAUSING ME PROBLEMS/////////////// WHAT SHOULD I ADD? var portTween:Tween = new Tween(homebtn,"x",Strong.easeOut,homebtn.x,-750,1,true);
portTween.addEventListener(TweenEvent.MOTION_FINISH, WhenTweenEnds); function WhenTweenEnds(e:TweenEvent):void {
trace("portfolio"); new Tween(topmenu,"y",Strong.easeOut,topmenu.y,0,1,true); } //////////////////////////////////////////////////////////////////////////////
new Tween(topmenu,"y",Strong.easeOut,topmenu.y,0,1,true);
You have to assign it to a variable:
Actionscript Code:
var topMenuTween:Tween = new Tween(topmenu,"y",Strong.easeOut,topmenu.y,0,1,true);
And before you ask another question about why does your tween gets stuck from time to time, I'll answer this:
Declare you're tween outside the function:
Actionscript Code:
var topMenuTween:Tween; function WhenTweenEnds(e:TweenEvent):void {
trace("portfolio"); topMenuTween = new Tween(topmenu,"y",Strong.easeOut,topmenu.y,0,1,true); }
And by the way, I do reccomend you to use caurina tweener, ot TweenLite instead these crappy built-in tweens
Cheers Ryan. I will have a play tonight and let you know how I go on. I use tweenMax/tweenLite occasionally but get scared sometimes and when im in a rush I dont have the time to search online for answers when I'm in a pickle.
With tweening like so:
Actionscript Code:
new Tween(topmenu,"y",Strong.easeOut,topmenu.y,0,1,true);
I am lazy. The tween worked without
Actionscript Code:
var topMenuTween:Tween =
in front of it, so did not understand why it should be used.
I did'nt notice the tween getting stuck anywhere :s Im gonn go click crazy and replicate it. But I will use your hint of declareing the tween outside the function.
You should assign your tween to a variable so you can manipulate it later if you have to. If you just want a tween that will never ever need to be accessed again or cancelled, then you can do it without a variable.
You should assign your tween to a variable so you can manipulate it later if you have to. If you just want a tween that will never ever need to be accessed again or cancelled, then you can do it without a variable.
Thats what I thought. I'm glad you confined this for me, otherwise I would have been doing something seriously wrong for the last 5 years ha.
I still havent had a chance to work on this problem yet, so busy with client work at the mo
You wrote a very bad code actually. It's almost unreadable without some refactoring, but since it's pretty small, I found the problem right away;
Look, here you try to add an event listener to an object that's not created yet:
Actionscript Code:
portfoliotween.addEventListener(TweenEvent.MOTION_FINISH, onFinish); // program: what is portfoliotween? I don't know. var portfoliotween:Tween = new Tween(themenu,"x",Strong.easeOut,themenu.x,-750,1,true);
And then you create an internal function that won't be accessible after the swich code has been completed:
Actionscript Code:
function onFinish(e:TweenEvent):void{ trace("portfolio"); }
I changed your code a little bit, and it worked fine:
trace("portfolio") var portfoliotween:Tween = new Tween(themenu,"x",Strong.easeOut,themenu.x,-750,1,true); portfoliotween.addEventListener(TweenEvent.MOTION_FINISH, onFinish);
Im more of a design than a developer but all I can do is learn learn and learn.
I also thought it was better to use Flash IDE for a design. Now I'm using FlashDevelop + Flex SDK 4 for all of my projects; sites, games, AIR apps. It's much better to write everything in classes than on a timeline. And also, it comes out cleaner and more human-readable.
As to graphics, you can easily embed them into your project by using constructs like this:
Actionscript Code:
[Embed(source="someimage.png")]privatevar SomeImage:Class; privatevar image:Bitmap = new SomeImage as Bitmap;