Solved

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

Posted on 2010-09-22
13
452 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 250 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 250 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

751 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