2 Replies - 22711 Views - Last Post: 18 October 2012 - 05:27 AM

#1 bentist  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 17-January 11

Apple-style "Daisy Loader"

Posted 17 January 2011 - 11:27 AM

Description: Instantiate the DaisyLoader class and then add to stage. When an instance of DaisyLoader is added to the display list, animation begins. When it is removed, animation stops.A class to display an aimated Apple-style loader
[CODE]

package com.utils
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	import flash.display.CapsStyle;
	import flash.display.LineScaleMode;
	
	/**
	*
	* Author: Ben Harrris (http://www.benharrisdesign.com)
	* 
	* Description: A class to display an aimated Apple-style loader
	* To use: Instantiate the DaisyLoader class and then add to stage. 
	* When an instance of DaisyLoader is added to the display list, animation begins.
	* When it is removed, animation stops.
	*
	*/
	
	
	public class DaisyLoader extends Sprite
	{
		private const NUM_PETALS:int = 12;
		private var _timer:Timer;
		
		public function DaisyLoader(color:Number = 0x999999)
		{
			// Create petals and rotate them eavenly around the center.
			for(var i:int = 0; i<= NUM_PETALS; i++)
			{
				var petal:Sprite = new Sprite()
				petal.graphics.lineStyle(3, color, 1, false, LineScaleMode.NORMAL, CapsStyle.ROUND)
				petal.graphics.moveTo(10, 0);
				petal.graphics.lineTo(16, 0);
				petal.rotation = i * (360 / NUM_PETALS);
				petal.alpha = i * (1 / NUM_PETALS);
				addChild(petal);
			}
			
			_timer = new Timer(50);
			
			this.addEventListener(Event.ADDED_TO_STAGE, on_added);
			this.addEventListener(Event.REMOVED_FROM_STAGE, on_removed);
		}
		
		private function on_added(evt:Event):void
		{
			_timer.start();
			_timer.addEventListener(TimerEvent.TIMER, on_timer);
		}
		
		private function on_removed(evt:Event):void
		{
			_timer.reset();
			_timer.removeEventListener(TimerEvent.TIMER, on_timer);
			this.rotation = 0;
		}
		
		private function on_timer(evt:TimerEvent):void
		{
			// Rotate DaisyLoader by 1 "petal"
			// Note: Another option is to fade petals to give the illusion of rotation. 
			// But rotation is probably more efficient than changing alpha.
			
			this.rotation += 360 / NUM_PETALS;
		}
	}
}


[/code]

Is This A Good Question/Topic? 0
  • +

Replies To: Apple-style "Daisy Loader"

#2 lizr0x  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-October 12

Re: Apple-style "Daisy Loader"

Posted 17 October 2012 - 06:22 PM

it says the package is unexpected
Was This Post Helpful? 0
  • +
  • -

#3 bentist  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 17-January 11

Re: Apple-style "Daisy Loader"

Posted 18 October 2012 - 05:27 AM

Sounds like you're not using this as an external actionscript class? I need more information. How are you trying to use it?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1