MPs return to choose next Speaker

John Bercow

MPs will come to the House of Commons later for the first time since the general election, where they will choose the next Commons Speaker.

Incumbent John Bercow is likely to return to the role, but not before facing a challenge from some MPs.

If enough call for a vote it would be the first such ballot in 175 years.

Following the formation of the coalition government, the Conservative and Liberal Democrat MPs are to sit on the same side of the Commons.

Labour’s stand-in leader Harriet Harman and her colleagues will be on the opposition benches for the first time since 1997.

Swearing in

Some 227 new MPs were elected for the on 6 May, resulting in a hung parliament and a subsequent Conservative-Lib Dem coalition.

MPs will begin being sworn in on Wednesday, assuming there is not a challenge to Mr Bercow, which would delay proceedings.

Sir Peter Tapsell, The Father of the House – meaning the MP with the longest continuous service – will preside over the appointment of the next Speaker, starting at about 1430 BST on Tuesday.

He will first ask for those supporting Mr Bercow, MP for Buckingham, to shout "Aye" and those opposing him to say "No".

Normally incumbent speakers are chosen unanimously at this stage. But if several MPs are determined to force a vote, they can do so.

There would then be a vote, with MPs passing through the lobbies.

If Mr Bercow loses this, a series of secret ballots take place until a new Speaker is chosen.

BBC deputy political editor James Landale said the process was unlikely to go this far, with Mr Bercow winning the lobby vote.

The Speaker has only been in place since last summer, when he replaced Michael Martin, who resigned over his handling of the MPs’ expenses scandal.

The last incumbent to be voted out was Charles Manners-Sutton, in 1835.

The swearing-in of MPs is expected to last into Thursday, with the most senior going first. MPs can take a religious oath or a secular affirmation of loyalty to the Crown.

The serious business of the Parliament gets under way next week, with the Queen’s Speech, outlining the coalition’s legislative agenda for the year, taking place on Tuesday.

This article is from the BBC News website. © British Broadcasting Corporation, The BBC is not responsible for the content of external internet sites.

BBC apology for Queen death joke

WM presenter Danny Kelly

The BBC has apologised after a radio presenter said the Queen had died.

Danny Kelly who works for BBC WM in the West Midlands, played the national anthem as he made the joke during his Birmingham-based afternoon show.

A BBC spokesman said it had been a reference to an item on one of his internet pages.

It was corrected on-air immediately and described as "entirely inappropriate" by a BBC spokesman who said the corporation apologised "unreservedly".

The spokesman added: "Although made as part of a light-hearted piece about social media friends, and corrected on-air immediately after it was made, the comment was entirely inappropriate and the BBC apologises unreservedly for it.

"There was no intention to offend.

"BBC WM takes this comment very seriously. Action is being taken."

The spokesman could not comment on what action had been taken following Mr Kelly’s comments and it is not yet known if he will present his afternoon show on Tuesday.

This article is from the BBC News website. © British Broadcasting Corporation, The BBC is not responsible for the content of external internet sites.

New dimension

Sam Worthington in Clash of the Titans

Avatar, Clash of the Titans and the upcoming Tintin trilogy – all of them big budget movies made in 3D.

But it’s not quite as straightforward as that.

The price you pay to watch a 3D movie at the cinema is always the same – but there are several ways of tricking your eyes into seeing that extra dimension and, according to some, the quality varies greatly.

Avatar, for example, was filmed entirely using a 3D camera system, which was partly developed by director James Cameron.

Other movies, including the forthcoming Harry Potter finale, are being shot with regular cameras and converted into 3D during post-production.

Clash Of The Titans director Louis Leterrier had wanted to use 3D cameras to shoot his Greek mythology epic – but the technology was so new, the only ones in existence had already been booked for Avatar.

Leterrier had reservations about the conversion process – which, in essence, cuts the picture into layers like a pop-up book – but ultimately, he was impressed with the result.

"It was absolutely amazing, just the amount of detail. It doesn’t look like cut-out people on flat backgrounds – everything was absolutely realistic," he told BBC 5 Live.

But not everyone agrees.

The original picture is filmed by two cameras at different angles. A 3D projector projects two images: from one angle......and from another angle. The two images are projected sequentially by a digital projector, and overlap on the screen.Polarised light reflects off a specially treated 'silver' screenSpecial glasses allow only one of the images into each eye as each lens has a different polarisation. The brain interprets the image in 3D

Film critic Roger Ebert enjoyed the film but ended his review in the Chicago-Sun Times with a warning: "Explain to kids that the movie was not filmed in 3D and is only being shown in 3D in order to charge you an extra $5 a ticket.

"I saw it in 2D, and let me tell you, it looked terrific."

The Daily Telegraph reviewer Sukadev Sandhu was also unimpressed.

"Part of the problem lies in transferring it to 3D," he wrote.

"Avatar raised the bar quite high for that format… here it feels random, superfluous, distinctly unspectacular. If you choose to take off your specs you’ll be missing very little."

Martin Hobbs of Prime Focus, the company which converted Clash of the Titans, says he was pleased with the outcome although admits it was converted quickly.

"There are shots that could have been done with a bit more time," he concedes.

"You need time to make a refined product."

Avatar

The film was converted in just eight weeks as opposed to the usual 12 – 15 weeks because making it into a 3D movie was "an afterthought", Hobbs explains.

To get the film ready in time, Prime Focus employees endured lots of overtime and director LeTerrier was very hands-on.

"He was completely involved, sometimes here up to three times a day," says Hobbs.

Hobbs is keen to point out he is not against making films in 3D – far from it.

"It’s not about one (process) or the other – you could shoot one scene in stereo and then choose to convert another one."

But Avatar director James Cameron has also hit out at the conversion process.

Darker image

Cameron said filming a movie in 3D assures better quality over the subsequent conversion.

Nonetheless, the film-maker has revealed wants to remake his 1997 blockbuster Titanic in 3D, but said it will be different because he plans to take his time instead of doing a "slapdash conversion".

Tim Burton, whose Alice in Wonderland movie was converted to 3D in post-production, believes the differences in quality are more about artistic vision than techniques.

Peter Jackson

"With all of these tools, you can see good 3D, bad 3D, good conversion and bad conversions," he said.

But not all film-makers are keen to jump on the 3D bandwagon.

British director Mike Newell (Harry Potter and the Goblet Of Fire, Four Weddings And A Funeral) filmed the bulk of his new movie, Prince Of Persia, in 2008 and some critics have expressed surprise that it was not given a 3D makeover on its journey to the big screen.

But he was adamant that the film would be seen the way it was shot.

"If you’re going to do a 3D conversion, what you have to do at this stage is to send it off to some bloke’s garage in South Korea and he’ll give it back to you in three months’ time and say ‘that’s your lot," he told the BBC.

"Nobody’s prepared to do that".

Referring to his fellow colleague Cameron, he added: "Sequences in Avatar, like the seeds falling like snow, have to be planned from the very beginning. You can’t just run it through a conversion process. Until Avatar was released, nobody knew."

Another hold-out is Pan’s Labyrinth director Guillermo Del Toro, who plans to make The Hobbit in 2D, according to producer Peter Jackson.

"Guillermo wants to shoot in 35mm, old-fashioned film," Jackson has said, "which suits me, because he wants to keep it in the same space as the original [Lord Of The Rings] trilogy".

Jackson has been keen not to over-emphasise the vogue for 3D, saying it "only adds to the experience" of watching a movie.

"The only thing I get annoyed about is the image being a little dull. It does feel like you’re looking at the movie with sunglasses on."

Indeed, that is probably the main downside for the viewer. The polarization process that creates the illusion of 3D results in a darker image on the screen, making films less vibrant.

But for just a few million dollars, a small percentage in a blockbuster budget, 2D films can be converted to 3D quite easily.

It is cheaper to convert than make in stereo – to make a film in 3D roughly adds about 30% to the budget, but the cost of conversion is unlikely to exceed $15m (£9.8m) dollars.

And with the extra bucks to be made at the box office, 3D movies show no signs of stopping.

This article is from the BBC News website. © British Broadcasting Corporation, The BBC is not responsible for the content of external internet sites.

‘Slave to football’

Saddam Maake

Sadaam Maake’s home would be a fitting shrine to the football gods. It is filled with football memorabilia such as tickets, trophy replicas and jerseys.

More than 200 "makarapa" plastic helmets and vuvuzelas (long trumpets) – both essential garb for any South African soccer fan – adorn Mr Maake’s tiny lounge.

Before our interview, he insists on "kitting up first"- he changes into a tracksuit in the colours of the national team Bafana Bafana and completes the look with oversized glasses.

"I am ready to talk about football now," he says, smiling.

At 55 years old, he says he has lost count of how many times he has been to a stadium.

"I’m a soccer slave. I drink football, I eat football, I talk football. Everything in my life revolves around soccer. It is my passion," says Mr Maake.

Mr Maake has been dubbed South Africa’s "number one football fan" by local media and Kaizer Chiefs, one of South Africa’s oldest and biggest clubs, which he has supported for 40 years.

‘Bitten by dogs’

An animated man, he speaks with great passion about the atmosphere in local football stadia.

"There are 80,000 people at a stadium at a go, all cheering and excited about the game. Here I make new friends.

"For 90 minutes, a brotherhood prevails here, strangers become instant friends," he says.

One of the unifiers at South Africa’s football matches is the sound of the vuvuzela. Mr Maake is the man who made thefamous here.

"If you don’t hear a vuvuzela playing at a game you are not in South Africa. This is our thing, international fans need to embrace it."

The trumpets will be blaring loudly at the World Cup, despite a number of attempts by some international clubs and commentators to have thembannedbecause of the noise.

"I’ve been arrested three times over the years and charged with public disturbance because of this vuvuzela. I’ve even been bitten by police dogs, but I will continue to play it," he said.

But he warns fans to be careful when blowing the instrument near children or people with sensitive hearing.

Local ambassador

Mr Maake says he cannot wait to see the national team play the world on home soil.

"This is a hell of a joint, it is the first – and perhaps the last – time we ever host the World Cup in Africa. We must do ourselves proud," he beams.

The avid fan adds that this is Africa’s time to shine. "Africa’s ‘six-pack’ – Nigeria, Ivory Coast, Cameroon, Algeria, SA and Ghana – must be in the final."

"The cup must stay in Africa."

Mr Maake is a local ambassador for the tournament – in the past year he has been touring the country educating people about the ticketing process.

He speaks candidly about the World Cup tickets, which still have not sold out.

"If the international fans don’t buy the tickets, we will. We will fill the stadia ourselves and cheer for their teams if we have to.

"The teams will play whether the fans are there or not. The game will go on, why should we be worried about ticket sales?" he asks.

Sixty-four matches will be played during the June sporting event.

Mr Maake’s 13 children all have tickets to a number of them.

"If it were up to me, I’d watch all the games. My family and I will go to all the games where South Africa and all the African countries are playing and some international teams like Portugal," he said.

Mr Maake, who lives in in Tembisa, east of Johannesburg, loves football so much he sings about it. He released an album some years ago named after his son Cellular, titled Vuvuzela Cellular.

"There is a lot of singing at stadia. I came up with the idea of an album because of that. I love singing about football because it makes fans happy."

He worked on it with his children.

Though none of the songs are likely to be chart-toppers, he still he has a large following in his home province of Limpopo.

A price worth paying?

Mr Maake’s obsessive love for the game has come at a price.

He has never wed, saying he has had difficulties finding a woman who understands his passion for football.

"No woman can put up with a man who travels every day of the week just for football. Even when I’m at home this is all I talk about," he laughs.

A collection of helmets at Saddam Maake's home

"Just look at how the lounge is decorated, what woman would like this," he asks pointing to the pile of helmets under a table in the lounge.

The relationship between makarapa and fans dates back to the 1970s when they were originally worn to protect the head from beer bottles thrown at riotous games.

Nowadays, they are purely decorative, with fans expressing their individuality by painting the helmets.

Mr Maake’s passion has also cost him his job – on several occasions.

He first worked at a retail store in Johannesburg and was later employed at a car rental company.

"I’d be called to disciplinary hearings all the time because I would miss work during the week if my team was playing. I just couldn’t miss a game.

"It just wasn’t working out; I didn’t try to find a job since. But my football has been taking care of me," he explains.

With a month to go to the World Cup, Mr Maake has started learning a few languages including French – all to welcome international visitors.

He has the basics down, but says the greatest welcome they will receive is the hospitality of South Africans and the buzz around the World Cup.

"We are ready, we are waiting. This is it," he cheers.

This article is from the BBC News website. © British Broadcasting Corporation, The BBC is not responsible for the content of external internet sites.

US parties in key elections test

electoral calendar map

Americans in several states are preparing to go to the polls to decide on party candidates for November’s mid-term elections.

The outcome of these primary ballots will be seen as a key indicator of the volatile political mood in America.

Two sitting Democratic senators are facing serious intra-party challenges, while the conservative Tea Party movement may claim a win in Kentucky.

Polls suggest anti-incumbent sentiment is rife across the US.

Senator Arlen Specter

"In America today voters don’t like or trust government, business or even the Catholic Church," Republican strategist Mark McKinnon told the BBC.

"The worst thing you can be is an incumbent. The Pope would have a hard time getting re-elected right now."

Veteran Pennsylvania Senator Arlen Specter, who was first elected in 1981, is fighting for his political life against two-term Democratic House Representative Joe Sestak.

Formerly a Republican, Mr Specter switched parties, becoming a Democrat in April 2009.

At the time, Mr Specter said it was because Republicans had shifted too far to the right, but pundits speculated that the switch was motivated by a looming primary challenge from a conservative Republican.

Now, Mr Specter may well lose to a challenger from his left, Mr Sestak, in a campaign where the former’s many years of experience and political weight in Washington have become liabilities.

Rand Paul campaigns in Kentucky

The latest polling shows the pair in a dead heat.

In Kentucky, two Republican candidates are vying for their party’s nomination for a Senate seat vacated by retiring Senator Jim Bunning.

Kentucky Secretary of State Trey Grayson has been anointed by the Republican establishment, most notably Senate Minority Leader Mitch McConnell and former Vice-President Dick Cheney.

But Rand Paul, son of one-time presidential candidate Ron Paul, has harnessed conservative grassroots energy, mounting a serious challenge to the party establishment’s favourite.

Driven by the burgeoning Tea Party movement, a win for Rand Paul would be the second victory in a matter of weeks for Tea Partiers, who recently helped displace sitting Utah Senator Bob Bennett as the Republican candidate in that state.

Outsiders’ energy

Also on Tuesday, a special election will be held to replace Democratic Congressman John Murtha, who died in February this year.

Mr Murtha’s seat was long considered a Democratic stronghold, but Republican candidate Tim Burns is polling well.

Both parties are viewing this race as an important preview of November’s elections.

They have funnelled over $2m (£1.4m) into the race and former President Bill Clinton recently campaigned there for the Democratic candidate.

"A Republican win in that seat could signal a really big Republican year," Scott Rasmussen, president and CEO of polling firm Rasmussen Reports, told the BBC.

But Mr Rasmussen cautions against over-interpreting the results for any one race. Rather, he says, the results should be looked at in concert.

"You have to look across the board. If Rand Paul wins his primary, if Joe Sestak wins his, and if the Republican wins [John Murtha’s former seat], then the energy really is with the outsiders," says Mr Rasmussen.

And insiders, as far as the public is concerned, appear to include Republicans.

Arkansas Senator Blanche Lincoln

"Rand Paul is really campaigning against Mitch McConnell. If he wins, that will send a clear message that Republicans aren’t immune," Mr Rasmussen says.

"It’s not that people have fallen in love with Republicans suddenly."

But Frank Newport, editor-in-chief of the Gallup Poll, warns Americans not to interpret Tuesday’s results "to excess".

"Every race is idiosyncratic to that district or that state," Mr Newport told the BBC, pointing out that, for example, Arlen Specter’s long history with Pennsylvania voters animates that contest.

In Arkansas, incumbent Democratic Senator Blanche Lincoln has problems on both the right and the left.

Ms Lincoln’s support for the economic bailout and health care reform angered Arkansas conservatives.

Meanwhile, liberals criticise Ms Lincoln for not supporting cap-and-trade energy legislation.

Appeasing the left could help her win her primary, but would certainly lead to a loss in the general election.

Ms Lincoln, like many Democrats in conservative states, has found herself between a rock and a hard place.

Are you voting in the primaries? How important an indicator are they of the political mood in the US? What outcome are you anticipating? Send us your comments Click here to add comments..

This article is from the BBC News website. © British Broadcasting Corporation, The BBC is not responsible for the content of external internet sites.

Sausage a day ‘raises heart risk’

Sausages

Eating processed meat such as sausages increases the likelihood of heart disease, while red meat does not seem to be as harmful, a study suggests.

A Harvard University team which looked at studies involving over one million people found just 50g of processed meat a day also raised the risk of diabetes.

But there was no such risk from eating even twice as much unprocessed meat, such as beef, lamb or pork.

This was despite the fact the two forms of meat have a similar fat content.

Writing in the journal Circulation, the researchers speculated that given the similar quantities of cholesterol and saturated fats, the difference may be explained by the salt and preservatives added to processed meats.

This is defined as any meat preserved by smoking, curing or salting and includes bacon, sausages, salami and other luncheon meats.

Salt can increase blood pressure in some people, a key risk factor for heart disease.

In animal experiments, nitrate preservatives can promote atherosclerosis and reduce glucose tolerance, which can in turn lead to heart problems and diabetes.

Similar lifestyle

The team from Harvard School of Public Health looked at 20 studies involving more than one million participants from 10 countries.

On average, each 50g serving of processed meat per day – the equivalent of a sausage or a couple of rashers of bacon – was associated with a 42% higher chance of developing coronary heart disease and a 19% higher risk of diabetes.

"Although cause-and-effect cannot be proven by these types of long-term observational studies, all of these studies adjusted for other risk factors," said Renata Micha, lead author.

"Also, the lifestyle factors associated with eating unprocessed meats and processed meats were similar, but only processed meats were linked to higher risk."

Victoria Taylor, senior heart health dietician at the British Heart Foundation, said: "If you like red meat, this can still be included as part of a balanced heart-healthy diet.

"Go for lean cuts and aim to cook from scratch using healthier cooking methods like grilling or baking. If you need to add flavour, then try using fresh and dried herbs, spices and chillies instead of salt."

A spokesman for BPEX, which represents pork producers, insisted processed meats could form part of a balanced diet.

He suggested further research was needed before any dietary recommendations could be made.

"Various studies indicate that high consumption of processed meat can be indicative of an overall poorly balanced diet: therefore it could be other aspects of the diet that are contributing to the increase in risk," he added.

This article is from the BBC News website. © British Broadcasting Corporation, The BBC is not responsible for the content of external internet sites.

Painful memory

Kim Phuc, centre, flees with other children after the napalm attack on their village

Kim Phuc, the Vietnamese girl in one of the unforgettable images of the Vietnam War , has been reunited by the BBC with Christopher Wain, the ITN correspondent who helped save her life 38 years ago.

When Chris last saw Kim, she was lying on a hospital bed with first-degree burns to more than half of her body, after a South Vietnamese napalm bomb attack.

It was 8 June 1972 and Chris and his crew had been in Vietnam for seven weeks, covering the conflict for ITN.

He remembers the day clearly: "That morning we’d arrived at the village of Trang Bang, which had been infiltrated by the North Vietnamese two days earlier. They were dug in, awaiting a counter-attack.

"In the late morning, two vintage Vietnamese bombers started to circle overhead – this wasn’t anything unusual, but because we had been into the village we knew something was going wrong."

Many of the villagers had already fled to the shelter of a temple, among them nine-year-old Kim.

"We thought this would be a safe place – but then I saw the plane – it got so close," she remembers.

"I heard the noise of the bombs then suddenly I saw the fire everywhere around me.

"I was terrified and I ran out of the fire. I saw my brother and my cousin. We just kept running. My clothes were burnt off by the fire."

Chris and his crew were about 400m from the point where the four canisters of napalm had exploded.

"There was a blast of heat which felt like someone had opened the door of an oven. Then we saw Kim and the rest of the children. None of them were making any sound at all – until they saw the adults. Then they started to scream."

Lasting memory

A Vietnamese photographer, Nick Ut, was also covering events in South Vietnam that day.

As Kim ran down the road, her arms outstretched and screaming for help, he took what is now seen as one of the most memorable images of the Vietnam War.

She was still running when Chris stopped her and poured water over her, while directing his crew to record the terrible scenes.

Kim Phuc is surrounded by Television crews and South Vietnamese troops following the napalm attack

"We were short of film and my cameraman, the late, great Alan Downes, was worried that I was asking him to waste precious film shooting horrific pictures which were too awful to use. My attitude was that we needed to show what it was like, and to their lasting credit, ITN ran the shots."

Nick took Kim to the nearest hospital, the US-run Saigon First Children’s Hospital. Shortly afterwards, his photograph and the film footage appeared all over the Western media.

One result was that everyone wanted to know what had happened to the little girl.

It was Chris who found Kim the following Sunday, in a small room at the British hospital.

"I asked a nurse how she was and she said she would die tomorrow," he says. So he got her moved to a specialist plastic surgery hospital, for life-saving treatment.

Kim stayed in hospital for 14 months and went through 17 operations, remaining in constant pain to this day.

Her image became a lasting memory for a generation – but the little girl herself disappeared from public view.

Powerful gift

Then, 10 years later, a journalist from Germany tracked Kim down.

She was at university studying medicine but the Vietnamese government cut short her studies and ordered her back to her village to be filmed and interviewed. She was now a propaganda tool.

Even when she succeeded in resuming her studies, this time in Cuba, she was still expected to fulfil her duties as a "symbol of war".

It was at Havana University that she met Toan, a fellow student from Vietnam. They married and took a honeymoon in Russia, which provided them with a unique opportunity to flee to Canada.

"I heard rumours that a lot of Cuban students stay in Canada on the way back from Moscow, when the plane stops to refuel. By doing this I was finally able to gain my freedom."

Kim settled down to a peaceful and anonymous life in Canada with her husband and two children, but in 1995 she was traced by another journalist and the picture was splashed across the front page of the Toronto Sun.

"I wanted to escape the picture because the more famous it got, the more it cost me my private life. It seemed to me that my picture would not let me go," she says.

However, the realisation came to her she did not have to remain an unwilling victim. The photo was, in fact, a powerful gift that she could use to help promote peace.

"I realised that now that I have freedom and am in a free country, I can take control of that picture," she says.

‘Impressive woman’

This idea led her to establish the Kim Phuc Foundation, which provides medical and psychological assistance to child victims of war.

Chris continued with ITN for another three years as defence correspondent, covering amongst other things the Yom Kippur War and the invasion of Cyprus. Later he moved to the BBC.

He retired in 1999 and never expected to see Kim again.

"At the time, it was just another story, though an appalling one. It was certainly the worst thing I ever saw.

"Later, when interest was rekindled, I felt that Kim was being used. That was why 10 years ago I declined a proposed on-screen reunion with her on the Oprah Winfrey Show – it sounded exploitative."

Now, having met Kim, he’s changed his mind, and no longer thinks of her as a victim of that picture.

"Despite everything that has happened to her, and all she’s endured, she’s become a very impressive woman."

It’s My Story – The Girl in the Picture, presented by Chris Wain, can be heard on BBC Radio 4 on Tuesday 18 May at 1600 BST and then afterwards on BBC iPlayer.

This article is from the BBC News website. © British Broadcasting Corporation, The BBC is not responsible for the content of external internet sites.

Countdown in Style With an Airport Terminal Timer

In this tutorial we’ll make a reusable countdown timer with a dynamic target date that can be set via XML. We’ll animate the numbers flipping down in the style of an old airport or train station status board. We’ll cover code, graphics creation and animation. What are you waiting for..?


Step 1: Set Up Your Flash File

Create a new Flash file (Actionscript 3) with these settings: 500×300, black background, and 30 fps.

Flash file setup

Step 2: Create the digit_bottom MovieClip

Create a new MovieClip called ‘digit_bottom’ and draw a rounded rectangle inside it approximately 36px wide by 50px tall. (A quick way to draw a rectangle with precise dimensions is to select the rectangle tool and Alt-click on the stage.)

Give the rectangle a gradient fill from #111111 (top) to #333333 (bottom) and a 2 px outline colored #333333.

Background image or animation

Step 3: Position the Rectangle

Position the rectangle so that the registration point of the MovieClip (the little ‘+’) is exactly halfway between the top and bottom and the left edge. If you made your rectangle 50px tall, then the y value should be -25.

Rectangle Properties

Step 4: Add the Number

Create a new layer and add a dynamic text field called ‘t_num’. Choose a font that has an airport or train station feel to it (like Helvetica, DIN, or Interstate). I’m using Helvetica Bold.

Set the Paragraph Format to centered, and remember to embed the fonts for the numbers 0–9.

Position the text field so it’s centered on the background rectangle.

Number text field

We’re going to be using this MovieClip as the base for another graphic, so take a moment to make sure it looks good.


Step 5: Add a Mask

Create a new layer on the timeline of the digit_bottom MovieClip and call it ‘mask’. Copy the rounded rectangle and Paste in Place on the mask layer (Edit > Paste in Place, or Command-Shift-V).

Select the top half of the mask rectangle and delete it.

Right-click the mask layer, choose Mask and make sure that it is masking all of the layers below it.

Create the Mask

Step 6: Create the digit_top MovieClip

Go into the Library, duplicate the digit_bottom MovieClip and name the new copy ‘digit_top’.

This MovieClip will be virtually identical to the digit_bottom clip, except the mask will be showing the top half of the graphics instead of the bottom.

Delete the graphics currently on the mask layer. Copy the rounded rectangle and again Paste in Place on the mask layer. This time select the bottom half and delete it.

The only other adjustment you might want to make here is to adjust the color of the text and the shading of the background rounded rectangle. I made the graphics in my digit_top clip a bit darker to simulate light coming from the top.

digit_top and digit_bottom clips

Step 7: Create the Digit MovieClip

Create a new MovieClip named ‘Digit’. Drag in the digit_top and digit_bottom MovieClips and position them both at 0,0. Give them the instance names ‘top1′ and ‘bottom1′.

Now copy both of the MovieClips (digit_top and digit_bottom), create a new layer, and Paste in Place a copy of each. Name the new copies ‘top2′ and ‘bottom2′.

You should now have 4 MovieClips inside your Digit MovieClip: 2 copies of digit_top and 2 copies of digit_bottom. I’ll explain why we’re setting it up like this in the next step.


Step 8: Animation Strategy

We have to do a bit of animation trickery to get the flipping numbers effect we want. Take a look at the diagram below of our Digit MovieClip (I’m rendering it in 3D just so you can see the layering more easily):

Digit Animation Diagram

Animation Step 1:

We start out with the bottom2 clip flipped upside down (using the scaleY property) and placed behind the top2 clip. At this point the 2 clips that are visible are top2 and bottom1. The numbers on these two clips correspond to each other, so they form a complete digit.

Animation Step 2:

Now we flip down the top2 clip to the center of the digit. At this point scaleY will be zero, so the clip won’t be visible. At the same time, we’re also flipping down the bottom2 clip, but this one we’ll flip all the way to the bottom. Since it’s behind top2, it won’t show until it flips past the halfway point. Now the 2 visible clips are top1 and bottom1. The numbers on these two clips don’t match, but that’s okay because this step only lasts for a brief moment.

Animation Step 3:

The top2 clip stays in the center as bottom2 continues to fall all the way down to the bottom. Once it’s in place the numbers on the visible clips (top1 and bottom2) again match to form a complete digit.

Animation Step 4:

At this point we’ll relayer and reset the positions of the 2 hidden clips to get ready for the next flip. Notice how the clips are in the same positions as Step 1, only reversed.


Step 9: Create the Clock MovieClip

Now that we have the individual Digit MovieClip set up, let’s build the clock.

Create a new MovieClip on the stage called ‘Clock’ with the instance name ‘clock’. Inside the new MovieClip place 9 copies of your Digit MovieClip; 2 for seconds, 2 for minutes, 2 for hours, and 3 for days. Give each digit an instance name. From left to right name them ‘digit0′, ‘digit1′, ‘digit2′, and so on.

Add some colons to separate the MovieClips and labels for each section. The design is up to you. I added a dark rounded rectangle as a background for my clock.

Lastly, add a dynamic text field called ‘t_date’. This is where we’ll show the target date the clock is counting down to. Remember to embed the font for this text field if you’re not using a system font.

Clock MovieClip

Step 10: Create the Digit Class

Create a new Actionscript file called ‘Digit.as’ and add this code to create the empty shell for the class:

package {

	import flash.display.MovieClip;

	public class Digit extends MovieClip {
		private const TOP:int = 0;
		private const BOTTOM:int = 1;

		private var _currentDigit:Array;
		private var _nextDigit:Array;
		private var _number:String = "0";

		// CONSTRUCTOR
		public function Digit() {
			_currentDigit = new Array( top1, bottom1 );
			_nextDigit = new Array( top2, bottom2 );

		}

	}

}

This doesn’t do much yet. We’ve got a couple of arrays to hold the 2 sets of digit_top and digit_bottom MovieClips. I’ve set up 2 constants, TOP and BOTTOM to help keep track of the top and bottom clips within those arrays. The _number variable will hold the digit that’s on display at any given time.

(Note: I’m using the underscore in my variable names to indicate private variables.)

Find your Digit MovieClip in the Library and assign this class to it in the Linkage settings.

Digit Class Linkage Settings

Step 11: Import the TweenLite Library

We’re going to be using the TweenLite library to animate our Digit MovieClip.

Download the AS3 version of the TweenLite library here.

Place the ‘com’ folder in the same directory as your main Flash file (or in your source path, if you’ve set up a different class path).

Add these two lines at the top of your Digit class, just below the MovieClip import:

import com.greensock.*
import com.greensock.easing.*

We’re barely going to scratch the surface of what TweenLite can do in this tutorial. For more information check out the TweenLite Documentation.


Step 12: Program the flipTo Animation

Add this function to your Digit class:

public function flipTo(num:String):void {
	_number = num;
	_nextDigit[TOP].t_num.text = num;
	_nextDigit[BOTTOM].t_num.text = num;

	// flip down the top of the digit to the halfway point
	TweenLite.to(_currentDigit[TOP], .15, {scaleY: 0, ease: Linear.easeNone});
	// flip the next digit bottom down
	TweenLite.to(_nextDigit[BOTTOM], .3, {scaleY:1, onComplete: flipComplete,  ease: Bounce.easeOut});
}

Here’s what’s happening, line by line:

  • This function accepts a String that will hold the digit we’ll be flipping to. The first line just sets our _number variable to hold that digit.
  • Next we set the text fields in the TOP and BOTTOM MovieClips in our _nextDigit array to display that same digit.
  • Then we use TweenLite to tween the scaleY property of the TOP MovieClip of the _currentDigit to 0. This gives the effect that it’s ‘falling’ toward the center of the digit.
  • The last line is another tween, this time animating the BOTTOM clip of the _nextDigit from the the top of the digit down to the bottom. Again we’re using the scaleY property to simulate this effect, but this time from -1 to 1. Since it’s tweening twice as far as the TOP clip, we give it twice the amount of time (.3 seconds instead of .15). When this tween finishes it will call a function called ‘flipComplete’. We’ll write that function in the next step.

Take another look at the diagram in Step 8 if you’re confused about the animation here.


Step 13: Add the flipComplete() Function

Add this function to the Digit class just below the flipTo function:

private function flipComplete():void {
	// swap digits
	var next:Array = _currentDigit;
	_currentDigit = _nextDigit;
	_nextDigit = next;

	// reset layering
	reset();
}

Once the flip animation completes we’ll run this function. It swaps the _currentDigit and _nextDigit arrays. After that’s done it calls a function named ‘reset’ to reset the clip layering and positions for the next flip. Let’s write that function now.


Step 14: Add the reset() Function

Add this function to the Digit class:

private function reset():void {
	addChild(_nextDigit[BOTTOM]);
	addChild(_currentDigit[TOP]);

	// flip up the next bottom to be behind the current top
	_nextDigit[BOTTOM].scaleY = -1;
	_nextDigit[TOP].scaleY = 1;
}

The first two lines in this function pop the _nextDigit BOTTOM and then the _currentDigit TOP to the top of the display list. I usually just use addChild() to do this because it requires less typing than using setChildIndex().

After the clips are re-layered, we set the scaleY properties so they’ll be ready for the next flip. This means changing _nextDigit[BOTTOM] from 1 to -1 and _nextDigit[TOP] from 0 to 1.

Again, check the diagram in Step 8 if you’re getting lost.


Step 15: Add to the Constructor

One thing we forgot to do is position the clips properly for the first flip animation. We can do that easily by adding a call to the reset function right in the Digit class constructor:

// CONSTRUCTOR
public function Digit() {
	_currentDigit = new Array( top1, bottom1 );
	_nextDigit = new Array ( top2, bottom2 );

	reset();
}

Step 16: Add the number() Function

One last thing we’ll need in our Digit class is a way to access the private _number variable from outside the class. We’ll add a simple accessor function:

public function get number():String {
	return _number;
}

Step 17: Create the Clock Class

Create a new ActionScript file named ‘Clock.as’. Paste in this code:

package {

	import flash.display.MovieClip;
	import flash.events.TimerEvent;
	import flash.media.Sound;
	import flash.utils.Timer;

	public class Clock extends MovieClip {
		private var _clockTimer:Timer;
		private var _targetDate:Date;

		// CONSTRUCTOR
		public function Clock() {

		}

	}

}

Not much here yet. Just importing some of the classes we’ll need. I also have a couple of private variables. _clockTimer will count down the seconds for us, and _targetDate will hold the date that we’re counting down to.


Step 18: Add the set() Function

Add this function to the Clock class just below the constructor:

// set the target date and start the countdown timer
public function set(date:Date):void {
	_targetDate = date;

	_clockTimer = new Timer(1000) // tick every second (1000 milliseconds)
	_clockTimer.addEventListener(TimerEvent.TIMER, update);
	_clockTimer.start();

	// display the target date above the clock
	t_date.text = _targetDate.toLocaleString().toUpperCase();

	// update the clock once here so it starts with the correct time
	update();
}

This is the function that we’ll use to set the target date for the clock. It accepts a date (of course) and assigns that to the _targetDate variable. It then instantiates our _clockTimer. The _clockTimer will call the update function once per second to update the digits.

After starting the timer, the function sets the t_date text with the target date. The toLocaleString() function ensures the date is displayed in the user’s local time zone.

The last line of this function calls update once to set the clock to the proper time. Otherwise it would display “000 00:00:00″ for one second until the first timer event.


Step 19: Add the update() Function

This function is a bit long because it’s where most of the work gets done. Add it to your Clock class:

private function update(e:TimerEvent = null):void {
	var now:Date = new Date(); // get the current time

	// find the difference (in ms) between the target and now
	var diff:Number = _targetDate.valueOf() - now.valueOf();
	if(diff <=0){
		// TIME'S UP!
		// do something cool here
		_clockTimer.stop();
		_clockTimer.removeEventListener(TimerEvent.TIMER, update);
		diff = 0;
	}

	// convert to seconds
	diff = Math.round(diff/1000);

	// number of days
	var days:int = Math.floor(diff/ (24 * 60 * 60));
	diff -= days*(24 * 60 * 60 );

	// number of hours
	var hours:int = Math.floor(diff / (60 * 60))
	diff -= hours*60 * 60;

	// number of minutes
	var min:int = Math.floor(diff/ 60);
	diff -= min*60;

	// seconds are all that remain
	var sec:int = diff;

	// create an array of strings to hold the number for each value
	var diffArr:Array = new Array(String(days), String(hours), String(min), String(sec));
	var diffString:String = ""
	var len:int = 3; // the first value (days) has 3 digits. All the rest have 2
	for each(var s:String in diffArr){
		// pad the string with a leading zero if needed
		while(s.length < len){
			s = "0"+s;
		}

		len = 2; // all the other values are 2 digits in length
		diffString += s; // add the padded string to the diffString
	}

	// go through each character in the diffString and set the corresponding digit
	for(var i:int = 0; i< diffString.length; i++){
		if(diffString.substr(i, 1) != this["digit"+i].number){
			this["digit"+i].flipTo(diffString.substr(i, 1));
		}
	}

}

This function accepts a TimerEvent as its parameter. The default value for this parameter is null. This allows us to call the function without sending a parameter, as we’re doing in the set function.

The first line of this function gets the current date and time as a Date object. Next, we find the difference between the current date and the target date (line 37). If the difference is 0 or less, then it’s past the target date, so we stop the _clockTimer (lines 38-44).

Since the difference in time between now and the target is calculated in milliseconds, we need to convert that into a nice readable display of days, hours, minutes, and seconds (lines 46-62). The math here is pretty simple as long as you know that there are 1000 milliseconds in a second, 60 seconds in a minute, 60 minutes in an hour and 24 hours in a day.

On line 65 we store all those values as elements in an array. Starting on line 68 we loop through each element and add it to a String of characters called ‘diffString’. While doing this we also add leading zeroes where necessary (line 71). So if our values for the clock were 30 days, 5 hours, 56 minutes, and 6 seconds the diffString would look like this: “030055606″.

The last thing this function does is loop through the characters in the diffString (using the charAt() method). For each character in the string we check to see if it’s different from the number currently displayed on the corresponding digit. This is easy because of the way we named our digit instances. If the number is not the same as the one currently displayed we tell that digit to flip to the number in the diffString.


Step 20: Add Sound

Find (or create) a good ticking sound that will play every time the clock updates. Import it into the Library of your Flash file and set the class name to ‘TickSound’ in the Linkage settings.

Tick Sound Linkage Settings

Add the _tickSound variable to the top of your Clock class just below the two other variables:

private var _clockTimer:Timer;
private var _targetDate:Date;
private var _tickSound:Sound = new TickSound();

And play the sound inside the update function:

_tickSound.play();

Step 21: Add the Main Document Class

Our countdown timer is complete, we just need some way to set the target date. Create a new Actionscript file called ‘Main.as’ with this code:

package {

	import flash.display.MovieClip;

	public class Main extends MovieClip {

		public function Main() {

			// set the target date for the clock
			var targetDate:Date = new Date();
			targetDate.setTime( Date.UTC(2010, 4, 28, 20, 00) );
			clock.set(targetDate);
		}
	}

}

All this does is set the target date for the Clock instance on the Stage. I’m using setTime() and Date.UTC() to convert the date to Universal Timecode. This way the date will be correct when it gets converted back to local time on the user’s computer. Also, remember that the months are zero-based. So, the month 4 is actually May, not April.

In your Flash file set the Document class to ‘Main’.

Set the Document Class

If you need a refresher on using the Document Class check out this Quick Tip.


Step 22: Test

Test your movie now and everything should work. Try changing the target date in the Main class and see how the countdown changes.

One potential downside to how we’ve set this up is that the target date is hard-coded in our SWF. That’s fine, but it would be cool if we could dynamically load the date so that we could reuse the countdown for different things.

Let’s see what we can do about that…


Step 23: Create the XML File

Create a new XML file in the same folder as your Flash file called ‘targetDate.xml’ (an XML file is just a plain text file). Add this to the XML file:

<targetDate>
	<year>2011</year>
	<month>3</month>
	<day>25</day>
	<hour>20</hour>
	<minute>21</minute>
</targetDate>

Using this format for our target date is pretty bloated (there is more markup than there is actual data), but it will keep things very clear for the purposes of this tutorial.


Step 24: Load the XML

Now let’s make some changes to our Main document class. Replace everything in that file with this code:

package {

	import flash.display.MovieClip;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.events.Event;

	public class Main extends MovieClip {

		// CONSTRUCTOR
		public function Main() {
			// load the XML
			var xmlLoader:URLLoader = new URLLoader();
			xmlLoader.addEventListener(Event.COMPLETE, onDataLoaded);
			xmlLoader.load( new URLRequest("targetDate.xml") );

		}

	}

}

You’ll notice we’ve imported some additional classes to help us load the XML file. In the constructor function we’re creating a new URLLoader instance to load the file for us. We attach an event listener that will call a function named ‘onDataLoaded’ when the file is finished loading.


Step 25: Add the onDataLoaded() Function

Add this function to the Main class:

private function onDataLoaded(e:Event):void {
	var xml:XML = new XML(e.target.data);

	var targetDate:Date = new Date();
	targetDate.setTime(Date.UTC(int(xml.year), int(xml.month), int(xml.day), int(xml.hour), int(xml.minute) ));

	clock.set(targetDate);
}

This function creates a new XML object from the file we loaded. We then create a new Date object from the values in the XML. We’re again using setTime() and Date.UTC() to convert the date to Universal Timecode. The final line is the same as before, it just sends the target date to our Clock instance.


Step 26: Wrap Up

That’s pretty much it for this one. There are a couple of enhancements you might like to make though:

  1. Depending on what you’re using the countdown for, you might want to do something special for the user when the countdown hits zero. You’d add this to the Clock class in the part of the update function that checks if the timer is at zero.
  2. As I mentioned, the format of our XML is pretty wasteful as it is. You might rather just pass in the date as a string via FlashVars, use a different data format (like JSON), or just reformat the XML to be a bit more compact.

Good luck! As always, post a comment and let me know what you think.