Solved

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

Posted on 2010-09-22
13
453 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
Suggested Courses

635 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