Solved

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

Posted on 2010-09-22
13
448 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
Comment Utility
Use this
_root["day" + i + "_reg"]

Open in new window

0
 

Author Comment

by:GodsHand
Comment Utility
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
Comment Utility
Do you have a link to a website?
0
 

Author Comment

by:GodsHand
Comment Utility
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
Comment Utility
When I trace this:

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

I get an "undefined" error.
0
 
LVL 19

Expert Comment

by:Albert Van Halen
Comment Utility
Does trace(_root["day_2_reg"]) give you 'undefined' as well ?
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:GodsHand
Comment Utility
Nope, if I trace:

trace(_root["day1_reg"]);

I get:

_level0.day1_reg
0
 
LVL 22

Expert Comment

by:kadaba
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
jQuery Time Off Event 20 41
jQuery one function to process 3 clicks 7 26
Hovering effect 9 28
Need sample Angular apps for study 4 30
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
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…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
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.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now