Solved

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

Posted on 2010-09-22
13
449 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
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 …
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

815 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