Adobe Flex Authors: Matthew Lobas, PR.com Newswire, Shelly Palmer, Kevin Benedict

Related Topics: Adobe Flex

Adobe Flex: Article

Cover Story: How to Increase the Frame Rates of Your Flash Movies

How's Your Need For Speed?

Collision Detection
Finally, results from hittesting code using MovieClip.hitTest will not be affected by Bitmap Caching, as hittesting is still calculated based upon the vector data of a movie clip, not the generated bitmap that you actually see. To prove this create a new movie clip and draw a circle inside it, drag it onto the first frame of the main timeline and give it an instance name of circle_mc. Now add the following code to the first frame of the main timeline:

trace("hit: "+this.hitTest(_root._xmouse,_root._ymouse,true))

Cropping and Scrolling

Scrolling large amounts of complex vector data or text was previously a very intensive task for the Flash Player, it still is. However, Macromedia has recognized this problem and has added a new feature to the latest release of the Flash Player that provides a solution to this particular problematic scenario

It is now possible for us to define a rectangular viewing window for a movie clip that basically visually crops the movie clip to a specified size and scrolls the content of the movie clip by a specified offset. The scrolling offset can then be changed to scroll the movie clip's content into view over a number of frames.

How Do I Use It?
As a fairly advanced feature, at present and for the foreseeable future, it can only be utilized through ActionScript. For this, a property has been added to all movie clips called scrollRect which we use to tell Flash to crop a movie clip and shift the position of its content.

The scrollRect property can be though of as a very simplified equivalent of the ScrollPane component but for scrolling movie clips. That is because it allows you to show a certain part of a movie clip and move the content around inside this viewing area all by setting the value of one ActionScript property. This property is set by specifying an object that contains four properties; these four properties define the size and the scrolling offset of the movie clip's content.

They are:

  • Width - width of the viewing rectangle
  • Height - height of the viewing rectangle
  • X - scrolling offset on the x-axis
  • Y - scrolling offset on the y-axis
A scrolling offset determines the number of pixels that the contents of the movie clip should be shifted in the opposite direction. So, for example a scrolling offset of 10 on the x- axis will move the movie clip's contents minus 10 pixels (10) along the x-axis.

We can create an object that defines a viewing rectangle as follows:

//define the viewing area and scrolling offset

And then pass this object to the movie clip we want to scroll by setting the value of the scrollRect property:

//scroll and crop the movie clip

This will basically crop the movie clip to a 100 * 100 square and the position of the movie clip's contents appears to have changed by 50 pixels along both the x and y axis. The movie clip's _width and _height will change to the cropped size of the movie clip after applying a scrollRect.


Local coordinate space A movie clip is always cropped and scrolled in its local coordinate space, from the top left hand corner which is zero on both the x and y axis (0, 0). You cannot move the viewing window of the movie clip; you can only move the content of the movie clip in the opposite direction to bring it into view.

The cropping gives the same effect as having a mask that is positioned at 0,0 in the movie clip's local coordinate space. That's a hard concept to grasp, so let's take a look at an example and see what happens when we apply it to a movie clip.

Below you will see a movie clip with an instance name of gradientMc that contains a 200 * 200 square filled with a gradient. That square is centered on the movie clips local original (0, 0). Therefore the squares top left hand corner in the movie clip's local coordinates starts at 100,100.

The following code defines a viewing area that is 100 * 100 in size with no scrolling offset:

//define the viewing area and no scroll offset

When we set the scrollRect property of this movie clip you can see below, that the movie clip has been cropped from, not around its local origin.


Scaling a movie clip will scale the size of the cropped area. For example, if you define the cropped area as a 100 * 100 rectangle:


And then you scale the movie clip to twice its size:

//resize the movie clip to 200%

You will find that the cropped area is now actually a 200 * 200 square.

Similarly, if you rotate a movie clip that has a scrollRect property defined, the coordinate space of the scrollRect is rotated as well. Therefore, if you were to rotate a movie clip by 90 degrees and change the scrolling offset on the x-axis (left and right) by setting the scrollRect property, the movie clips content will actually scroll along the y-axis (up and down):


Removing the cropping and scrolling Retrieving the value of a movie clip's scrollRect property actually returns a copy of its original scrollRect. It doesn't return the original, which is a shame because it means we can't do something like this:

//doesn't work

Instead you have to get a copy of the original scrollRect, change its properties and then reapply it:

var s=scrollingMovieclip.scrollRect
//store a copy of the scrollRect property
s.x+=10 //change the xaxis
scrolling offset
//reapply with our changed copy

That also means that you can't simply delete the scrollRect property of a movie clip to remove it:

delete scrollMovieClip.scrollRect
//doesn't work

You have to explicitly set the scrollRect property of a movie clip to undefined to remove the cropping and scrolling:

//remove the cropping and scrolling

More Stories By Guy Watson

Guy Watson (aka FlashGuru) has been a well-recognized figure in the Flash community for around four years, supporting the community with tutorials and source files, moderating the large Flash community forums, and running his own Flash resource Web site - FlashGuru's MX 101. Guy was one of the two developers that created the award-winning zoom interface for Relevare and now works for Endemol UK, the creative force behind reality television, producing programs such as Big Brother and The Salon. Guy now spends most of his time developing Flash games and applications for high-profile clients such as Channel 5 Television, Ladbrookes, and UK Style.

Comments (24) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

Most Recent Comments
Conference Call 07/07/06 04:45:58 PM EDT

Trackback Added: Conference Call; Conference Call

Drug Rehab 07/07/06 09:19:22 AM EDT

Trackback Added: Drug Rehab; Drug Rehab

Payday Loan 07/05/06 10:59:50 AM EDT

Trackback Added: Payday Loan; Payday Loan

Dental Insurance 07/05/06 10:33:31 AM EDT

Trackback Added: Dental Insurance; Dental Insurance

Data Recovery 07/04/06 08:38:25 AM EDT

Trackback Added: Data Recovery; Data Recovery

Printers 07/02/06 12:24:47 PM EDT

Trackback Added: Printers; Printers

1031 Exchange 07/01/06 02:08:26 PM EDT

Trackback Added: 1031 Exchange; 1031 Exchange

First Aid Kits 07/01/06 03:49:12 AM EDT

Trackback Added: First Aid Kits; First Aid Kits

Car Accident Lawyer 06/30/06 02:25:19 PM EDT

Trackback Added: Car Accident Lawyer; Car Accident Lawyer

Acne 06/25/06 02:22:46 PM EDT

Trackback Added: Acne; Acne

Equity Line Of Credit 06/25/06 07:38:23 AM EDT

Trackback Added: Equity Line Of Credit; Equity Line Of Credit

Forklift 06/25/06 07:22:27 AM EDT

Trackback Added: Forklift; Forklift

Term Life Insurance 06/24/06 04:21:24 AM EDT

Trackback Added: Term Life Insurance; Term Life Insurance

Eye Surgery 06/23/06 06:58:00 PM EDT

Trackback Added: Eye Surgery; Eye Surgery

Relocation 06/23/06 06:35:57 PM EDT

Trackback Added: Relocation; Relocation

Payday Loan 06/23/06 06:33:04 PM EDT

Trackback Added: Payday Loan; Payday Loan

Payday Loan 06/23/06 03:15:54 PM EDT

Trackback Added: Payday Loan; Payday Loan

Relocation 06/23/06 03:10:34 PM EDT

Trackback Added: Relocation; Relocation

Distance Education 06/23/06 01:29:59 AM EDT

Trackback Added: Distance Education; Distance Education

Relocation 06/22/06 09:36:41 PM EDT

Trackback Added: Relocation; Relocation

Vasectomy 06/22/06 12:31:50 PM EDT

Trackback Added: Vasectomy; Vasectomy

Aeon 05/27/06 03:21:41 AM EDT

This tutorial is full of syntax errors.
Functions aren't terminated properly, statements aren't properly closed with semi-colons ;.
Needs amendment.

eddyC 02/19/06 07:05:15 PM EST

Hi "noname", I was searching for a solution to this problem and found out you've had the same tysRect-problem... Have you solved it by now? :-) TIA!

noname 01/05/06 06:00:11 PM EST

hey, i just took a shot at the example in "Cover Story: How to Increase the Frame Rates of Your Flash Movies": "Scrolling Large Amounts of Text".

Unless i'm doing something incredibly wrong, it's not close to complete the way you have it in the article. Anyway, i think i've narrowed it down and just need the value for one last property: "tysRect", in the scroll() function.

what is this supposed to be set to??? is there a working fla anywhere?


IoT & Smart Cities Stories
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City and will bring together Cloud Computing, FinTech and Blockchain, Digital Transformation, Big Data, Internet of Things, DevOps, AI, Machine Learning and WebRTC to one location.
In an era of historic innovation fueled by unprecedented access to data and technology, the low cost and risk of entering new markets has leveled the playing field for business. Today, any ambitious innovator can easily introduce a new application or product that can reinvent business models and transform the client experience. In their Day 2 Keynote at 19th Cloud Expo, Mercer Rowe, IBM Vice President of Strategic Alliances, and Raejeanne Skillern, Intel Vice President of Data Center Group and G...
DXWorldEXPO LLC announced today that All in Mobile, a mobile app development company from Poland, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. All In Mobile is a mobile app development company from Poland. Since 2014, they maintain passion for developing mobile applications for enterprises and startups worldwide.
Founded in 2000, Chetu Inc. is a global provider of customized software development solutions and IT staff augmentation services for software technology providers. By providing clients with unparalleled niche technology expertise and industry experience, Chetu has become the premiere long-term, back-end software development partner for start-ups, SMBs, and Fortune 500 companies. Chetu is headquartered in Plantation, Florida, with thirteen offices throughout the U.S. and abroad.
DXWorldEXPO | CloudEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
The standardization of container runtimes and images has sparked the creation of an almost overwhelming number of new open source projects that build on and otherwise work with these specifications. Of course, there's Kubernetes, which orchestrates and manages collections of containers. It was one of the first and best-known examples of projects that make containers truly useful for production use. However, more recently, the container ecosystem has truly exploded. A service mesh like Istio addr...
CloudEXPO New York 2018, colocated with DXWorldEXPO New York 2018 will be held November 11-13, 2018, in New York City and will bring together Cloud Computing, FinTech and Blockchain, Digital Transformation, Big Data, Internet of Things, DevOps, AI, Machine Learning and WebRTC to one location.
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22nd international CloudEXPO | first international DXWorldEXPO and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time t...
SYS-CON Events announced today that DatacenterDynamics has been named “Media Sponsor” of SYS-CON's 18th International Cloud Expo, which will take place on June 7–9, 2016, at the Javits Center in New York City, NY. DatacenterDynamics is a brand of DCD Group, a global B2B media and publishing company that develops products to help senior professionals in the world's most ICT dependent organizations make risk-based infrastructure and capacity decisions.