Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-28-2007, 03:21 AM   #1
Registered User
Join Date: Sep 2004
Posts: 61
Talking creating properties for sprite


I'm trying to create two new properties called startX and startY that I can use with a Sprite.

so when I create

var eachBall:Sprite = Sprite(new AnimateBall());
I can set the property startX and startY like so

eachBall.startX = eachBall.x
eachBall.startY = eachBall.y;
this doesn't need to override the x and y it's just merely a datastore. Any ideas how I can accomplish this?

saveth is offline   Reply With Quote
Old 07-28-2007, 04:22 AM   #2
Registered User
Join Date: Sep 2004
Posts: 61

I was able to get a little farther, I created a class that extends sprite and added in two getters and setters for startX and startY. I'm getting another error now though on the two lines of code below.

this.getChildByName("myBall_"+i).x = this.getChildByName("myBall_"+i).startX+Math.sin(angleX)*range;
this.getChildByName("myBall_"+i).y = this.getChildByName("myBall_"+i).startY+Math.cos(angleY)*range;
It says that startX and startY are not propertys of type DisplayObject. Why is it considering what I would think would be Sprite as a display object? The full code is below.


package com.crylounge
	import flash.display.*;
	import flash.media.*;
	import flash.net.*;
	import flash.utils.ByteArray;
	import flash.events.*;
	import flash.geom.*;
	import com.crylounge.ExtendSprite
	public class RaveWaveformVisualization extends BaseVisualization
		private var angleX:Number = 0;
		private var angleY:Number = 0;
		private var range:Number;
		private var xspeed:Number = .1;
		private var yspeed:Number = .1;
		public var AnimateBall:Class;
		override protected function updateDisplayList(w:Number, h:Number):void
			super.updateDisplayList(w, h);
		override protected function drawVisualization(e:Event):void
			if( !this.visible ) return;
			SoundMixer.computeSpectrum(spectrum, true, 2);
			var vol:Number = 0;
			for (var i:uint = 0; i <256; i++) {
				var fft:Number = spectrum.readFloat()*12;
				//vol is percieved loudness - generated by combining all 512 'lev' values//
				vol += fft;
				range = fft*50;//vol*2;
				if (this.getChildByName("myBall_"+i)) {
					this.getChildByName("myBall_"+i).scaleX = this.getChildByName("myBall_"+i).scaleY = fft;
					this.getChildByName("myBall_"+i).x = this.getChildByName("myBall_"+i).startX+Math.sin(angleX)*range;
					this.getChildByName("myBall_"+i).y = this.getChildByName("myBall_"+i).startY+Math.cos(angleY)*range;
					angleX += xspeed;
					angleY += yspeed;
		public function makeCircles():void {
			for (var j:uint = 0; j <256; j++) {
				var eachBall:ExtendSprite = ExtendSprite(new AnimateBall());
				eachBall.name = "myBall_"+j;
				eachBall.x = 380 - 5;
				eachBall.y = j*2+30;
				eachBall.startX = eachBall.x;
				eachBall.startY	= eachBall.y;
				this.rotation = 45;
				this.x = 300;
				this.y = - 180;
saveth is offline   Reply With Quote
Old 07-30-2007, 03:33 PM   #3
dr_zeus's Avatar
Join Date: Mar 2005
Location: Silicon Valley
Posts: 1,999

Sprite is a subclass of DisplayObject. The function getChildByName() will return any DisplayObject, but you need to tell it when you're returning something more specific, like an instance of your AnimateBall class. See fixed code below where I cast the result of getChildByName() as AnimateBall.

ActionScript Code:
this.getChildByName("myBall_"+i).x = AnimateBall(this.getChildByName("myBall_"+i)).startX + Math.sin(angleX)*range;
Josh Tynjala | Feathers
dr_zeus is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Wierd Timeline Transition Error Benaiah Other Flash General Questions 1 08-01-2006 04:32 PM
dynamically creating properties within classes systems ActionScript 2.0 3 06-19-2006 11:30 PM
cannot set/get properties on class instance - why? kracko ActionScript 2.0 10 08-07-2005 08:26 PM
creating an array of objects with properties mcmcom Components 3 08-24-2004 05:31 PM

All times are GMT. The time now is 04:17 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.