Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Incrementing instance name + number, but need to add text to instance name after the incremented number

Posted on 2010-09-22
13
Medium Priority
?
455 Views
Last Modified: 2013-11-11
This is probably really stupid, but I can't figure it out.

I have a simple loop:
for (i=1; i < 7; i++)
{
	_root["day"+i].onRollOver = function()
	{
		TweenLite.to(this, animTimeIn, { frameLabel:"open", _xscale:xscale, _yscale:yscale, ease:Bounce.easeOut } );
		TweenLite.to(_root["day"+i], animTimeIn, { _xscale:xscale, _yscale:yscale, ease:Bounce.easeOut } );
	}

Open in new window


Don't need to paste the rest. But for the second TweenLite.to... I have it as _root["day"+i]. But the instance is actually like day1_reg, day2_reg, day3_reg, etc. So for the life of me, I can't figure out how to add _reg to that _root["day"+i].

Any ideas?
0
Comment
Question by:GodsHand
13 Comments
 
LVL 19

Expert Comment

by:Albert Van Halen
ID: 33738230
Use this
_root["day" + i + "_reg"]

Open in new window

0
 

Author Comment

by:GodsHand
ID: 33738259
See, I did that, but it doesn't actually animate that object. I don't get any errors either...
0
 
LVL 19

Expert Comment

by:Albert Van Halen
ID: 33738371
Do you have a link to a website?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:GodsHand
ID: 33738488
Unfortunately no. I can't attach the FLA either because I'm using artwork that we can't share. I'm not getting it. Must be a limitation with TweenLite?
0
 

Author Comment

by:GodsHand
ID: 33738515
When I trace this:

trace(_root["day" + i + "_reg"]);

I get an "undefined" error.
0
 
LVL 19

Expert Comment

by:Albert Van Halen
ID: 33738583
Does trace(_root["day_2_reg"]) give you 'undefined' as well ?
0
 

Author Comment

by:GodsHand
ID: 33738592
Nope, if I trace:

trace(_root["day1_reg"]);

I get:

_level0.day1_reg
0
 
LVL 22

Expert Comment

by:kadaba
ID: 33738612
The problem with the code is that the i is not available when the function runs.
I googled it and got a similar concept which seems sound to have the instance in an array and attach the event to the instance...

http://forums.greensock.com/viewtopic.php?f=1&t=2583

hope that helps.
0
 

Author Comment

by:GodsHand
ID: 33738754
That kinda makes sense, but it still doesn't work:


import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;

TweenPlugin.activate([FramePlugin, FrameLabelPlugin]);

var animTimeIn:Number = 1;
var animTimeOut:Number = 0.5;
var yscale:Number = 115;
var xscale:Number = 115;

var objects:Array = [day1_reg];

for (i=0; i <= 24; i++)
{
	_root["day"+i].onRollOver = function()
	{
		TweenLite.to(this, animTimeIn, { frameLabel:"open", _xscale:xscale, _yscale:yscale, ease:Bounce.easeOut } );
		TweenLite.to(objects[i], animTimeIn, { _xscale:xscale, _yscale:yscale, ease:Bounce.easeOut } );
	}

	_root["day"+i].onRollOut = function()
	{
		TweenLite.to(this, animTimeOut, { frameLabel:"close", _xscale:100, _yscale:100 } );
	}
}

Open in new window

0
 
LVL 11

Assisted Solution

by:petiex
petiex earned 1000 total points
ID: 33746545
As kadaba said, the i variable is never declared as a variable.

Try changing

for (i=0; i <= 24; i++)

to
 
for (var i:int=0; i <= 24; i++)
0
 
LVL 8

Accepted Solution

by:
ActionScript_Helper earned 1000 total points
ID: 33760311
Problem may be with loop, the code uses last value of "i" instead of relavant, try using attached code:

Hope it will be helpful.
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;

TweenPlugin.activate([FramePlugin, FrameLabelPlugin]);

var animTimeIn:Number = 1;
var animTimeOut:Number = 0.5;
var yscale:Number = 115;
var xscale:Number = 115;

for (i=0; i <= 24; i++)
{
	var dayMovie = _root["day" + i + "_reg"];
	dayMovie.onRollOver = function()
	{
		TweenLite.to(this, animTimeIn, { frameLabel:"open", _xscale:xscale, _yscale:yscale, ease:Bounce.easeOut } );
		TweenLite.to(this, animTimeIn, { _xscale:xscale, _yscale:yscale, ease:Bounce.easeOut } );
	}

	dayMovie.onRollOut = function()
	{
		TweenLite.to(this, animTimeOut, { frameLabel:"close", _xscale:100, _yscale:100 } );
	}
}

Open in new window

0
 
LVL 37

Expert Comment

by:CyanBlue
ID: 34078410
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question