Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Flex > Flex 2, 3 & 4

Reply
 
Thread Tools Rate Thread Display Modes
Old 07-28-2007, 03:21 AM   #1
saveth
Registered User
 
Join Date: Sep 2004
Posts: 61
Talking creating properties for sprite

Hi,

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

so when I create

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

Code:
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?

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

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.

Code:
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.

Thanks,
Saveth

Code:
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;
		
		[Embed(source="/images/AnimateBall.swf")]
		[Bindable]
		public var AnimateBall:Class;
		
		override protected function updateDisplayList(w:Number, h:Number):void
		{
			super.updateDisplayList(w, h);
			makeCircles();
		}
		
		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.addChild(eachBall);
				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
Feathers
 
dr_zeus's Avatar
 
Join Date: Mar 2005
Location: Silicon Valley
Posts: 1,999
Default

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
Reply


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 07:41 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.