Solved

Changing the size a movie clip with action script

Posted on 2007-11-24
8
160 Views
Last Modified: 2010-04-03
I'm trying to get a handle on how AS works, and I came across an answer to a question that looks simple enough that I could learn exactly how it works. The script is at: http://www.experts-exchange.com/Software/Photos_Graphics/Web_Graphics/Macromedia_Flash/Q_22828685.html
My questions are:
1) How and where do I define TargetWidth?
2) What do I need to define in the line: clearInterval(myIntervalIDThatISetEarlier); and how and where do I define it?
3) How do I define what myMovieClip is? If it's called "testMC_", where do I put it, and how does the script know it.

In other words, I am still so ignorant that I need to know absolutely everything on the timeline necessary for the script to produce its intended results.

Thanks!
John

if (myMovieClip._width < myTargetWidth){
  myMovieClip._width++;  // this increments it by one
} else {
 clearInterval(myIntervalIDThatISetEarlier);
}
0
Comment
Question by:gabrielPennyback
  • 4
  • 4
8 Comments
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 20344943
1.
'myMovieClip' is the instancename of movieClip which you want to resize. you may replace it with your  movieClip instancename.

2.
'myTargetWidth' is a variable which should be set the the number of pixels you want that movieClip should resize.
for example:
myTargetWidth = 400;

alternatively, you can simply use 400 in place of 'myTargetWidth'


3.
clearInterval(myIntervalIDThatISetEarlier);

above line of code is actually, stopping an setInterval function which is being called repeatedly.

see following link for more details on 'setInterval' and 'clearInterval'
http://livedocs.adobe.com/flash/9.0/main/00001216.html


0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 20346211
Thanks.  I tried the link, but unfortunately I can't figure out anything from a tutorial until I have an example of exactly what the finished product looks like! so the next part of my question is:
What is "myIntervalIDThatISetEarlier"?  Is that something that has to be defined? If so, where and how is it defined? (I'm sure trhe answer is at the link, but I can't figure it out because I don't understand the meaning of terms like: scope, methodName etc., and although i've read a lot of Flash Help items, it never explains the meaning of these terms in a way that this beginner can understand).

Anyway, I have a movie clip of a rotating suare with the instance name "myMovieClip". And my code  inFrame 1 is:
if (myMovieClip._width < 400px){
  myMovieClip._width++;  // this increments it by one
} else {
 clearInterval(myIntervalIDThatISetEarlier);
}

I get an error message saying that in Frame 1, Line 1: ')' expected, but of course as is typical of Flash errors, it doesn't explain where the ")' goes.
Please let me know exactly what my code should be>

Thanks!
John
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 20346226
yes, 'myIntervalIDThatISetEarlier' is a normal variable which stores the pointer to a 'setInterval()' object
which is being used as a reference to the running setInterval()

clearInterval() function needs a reference to the setInterval() method to stop it.

hence,
in following line of code 'clearInterval()' method is stopping a setInterval() execution by using its pointer/reference stored in the variable "myIntervalIDThatISetEarlier"

clearInterval(myIntervalIDThatISetEarlier);

I hope it would be clear

-------------------
Aneesh Chopra
-------------------
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:gabrielPennyback
ID: 20347875
Hi Aneesh,
I wish it were clear to me, but it still isn't.
I got rid of the error message by eliminating the px after 400, so now the code has no errors, but it doesn't increase the size of myMovieClip (104px square).

Also, the code doesn't contain the phrase setInterval ... I only see clearInterval() ...... and what do you mean by" it's pointer/reference is stored in the variable "myIntervalIDThatISetEarlier"?  Where is that variable defined?
And are you saying that there is something in the variable "myIntervalIDThatISetEarlier" that is pointin/refering to the clearInterval() method?

Please give me the Action Script exactly as it should appear in my frame action, and tell me everything else I need to do in order for my rotating suare (104 x 104) to increase in size to 400 x 400.

And please forgive my denseness. I started out 2 years ago asking similarly dumb questions about VBA in Excel, and I have actually become quite proficent in that area.

Thanks!
John

CURRENT CODE:
if (myMovieClip._width < 400){
  myMovieClip._width++;  // this increments it by one
} else {
 clearInterval(myIntervalIDThatISetEarlier);
}
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 20348328
I suggest you to upload your sample FLA,
I will review whole existing code and update it according to your requirement

and finally, I will upload the udpated version for your review.

-------------------
Aneesh Chopra
-------------------
0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 20348444
Thanks, Aneesh
Here is the link to the file:http://www.designamania.com/MichaelTekstra/resizeMC.fla
John
0
 
LVL 34

Accepted Solution

by:
Aneesh Chopra earned 500 total points
ID: 20348471
Just replace your complete code with following

little explaination about 'setInterval'

it is method with takes minimum two parameters,
first param: name of the function which need to be executed continuously
second param: duration in millliseconds, which decide the interval inbetween repeatative execution of the function.

I hope it would be clear now
function resizeBox()
{
	if (myMovieClip._width<400)
	{
		myMovieClip._width += 3;// this increments it's width by 3
		myMovieClip._height += 3;// this increments it's height by 3
	}
	else
	{
		//clear running setinterval and stop the movieClip rotation
		myMovieClip.stop();
		clearInterval(myIntervalIDThatISetEarlier);
	}
}
//
var myIntervalIDThatISetEarlier = setInterval(resizeBox, 20);

Open in new window

0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 20351747
Awesome, thanks aneesh! And thanks for the education.  I'm sure I will have more similar questions today.

Thanks again,
John
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

Suggested Solutions

Title # Comments Views Activity
video live streaming 1 125
Can't play streaming video on event.on24.com 7 353
Actionscript in Flash 3 72
Can't enable Flash on Chrome 32 Windows 7 any more 2 29
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
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…
The goal of the tutorial is to teach the user how to how to record live broadcast.
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.

830 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