Log in

View Full Version : Passing Parameters in functions



Nile
05-28-2009, 03:44 PM
Hi, I need help in AS 3. My code looks like this:

import fl.transitions.Tween;
import fl.transitions.easing.*;

var hover:Array = new Array("car1", "car2", "car3", "car4", "car5", "car6");

addEventListener(Event.ENTER_FRAME, applyEffect);

function applyEffect(e:Event):void
{
for(var i:Number = 0; i < (hover.length); i++){
(hover[i]).addEventListener(MouseEvent.MOUSE_OVER, makeBigger);
}
}
function makeBigger(MouseEvent):void
{
var tweenW:Tween = new Tween(hover[i], width, Strong.easeOut, hover[i].width, hover[i].width*2, 1);
var tweenH:Tween = new Tween(hover[i], height, Strong.easeOut, hover[i].height, hover[i].height*2, 1);
}

But I'm getting these errors (highlighted whats wrong too).



1120: Access of undefined property i.
1067: Implicit coercion of a value of type Number to an unrelated type String.
1120: Access of undefined property i.
1120: Access of undefined property i.
1120: Access of undefined property i.
1067: Implicit coercion of a value of type Number to an unrelated type String.
1120: Access of undefined property i.
1120: Access of undefined property i.


I know why, but I don't know how to fix it. I'm making a sort of gallery thing, here's a screen shot.
http://localhostr.com/files/635af2/capture.png


Changed my code to this:


import fl.transitions.Tween;
import fl.transitions.easing.*;

var hover:Array = new Array("car1", "car2", "car3", "car4", "car5", "car6");

addEventListener(Event.ENTER_FRAME, applyEffect);

function applyEffect(e:Event):void
{
for(var i:Number = 0; i < (hover.length); i++){
(hover[i]).addEventListener(MouseEvent.MOUSE_OVER, makeBigger);
}
}
function makeBigger(MouseEvent):void
{
var tweenW:Tween = new Tween(this, "width", Strong.easeOut, this.width, (this.width)*2, 1);
var tweenH:Tween = new Tween(this, "height", Strong.easeOut, this.height, (this.height)*2, 1);
}


But when I go to Debug Movie, I get:
http://localhostr.com/files/511c7b/capture.png


I tried using parameters, but it didn't work either. I'm guessing it has something to do with the array.




OK, I solved part of my problem, here's my code:


import fl.transitions.Tween;
import fl.transitions.easing.*;

var hover:Array = new Array(car1, car2, car3, car4, car5, car6);

addEventListener(Event.ENTER_FRAME, applyEffect);

function applyEffect(e:Event):void
{
for(var i:Number = 0; i < (hover.length); i++){
(hover[i]).addEventListener(MouseEvent.MOUSE_OVER, makeBigger(i));
}
}
function makeBigger(num:Number):void
{
var tweenW:Tween = new Tween(hover[num], "width", Strong.easeOut, hover[num].width, hover[num].width*2, 1, true);
var tweenH:Tween = new Tween(hover[num], "height", Strong.easeOut, hover[num].height, hover[num].height*2, 1, true);
}

Here's an example: http://unlinkthis.net/examples/flash/gallery/gallery.swf
HELP

Medyman
05-28-2009, 10:08 PM
Can you summarize where you are at the moment and what errors, if any, you're getting? Also, what is your desired end result?

Nile
05-29-2009, 11:13 PM
I want this:
When I hover over the image, it enlarges, mouse out, it gets smaller.

I don't know why the yellow car gets larger with out me hovering it, but I do know why it keeps enlarging.

This is what hapens when I click debug -> debug mvoie:
http://localhostr.com/files/19f605/capture.png

If you wish to download the files, download them here (http://localhostr.com/files/9fbc06/Gallery.tar) (tar format).

Nile
05-31-2009, 01:13 PM
No body? Been more than a day.