Flash Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignFlash Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 3rd, 2004, 03:43 AM
blatant's Avatar
blatant blatant is offline
World Domination
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: San Diego
Posts: 126 blatant User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 17 sec
Reputation Power: 6
Send a message via AIM to blatant
class problems

I'm having a problem with classes. I have two class definitions, photo and photoCategory as follows:
Code:
class photo 
{
	var fileName:String;		this.caption = caption;		
	}
}

class photoCategory 
{
	var name:String;
	var photos_arr:Array = new Array();
	var path:String;
	
	function photoCategory(name:String,path:String)
	{
		this.name = name;
		this.path = path;
	}
	
	function addPhoto(thePhoto:photo)
	{		
		photos_arr[photos_arr.length] = thePhoto;
		trace("adding photo: "+thePhoto.fileName+" to category: "+name+", total length is now: "+photos_arr.length);
	}
}


when I add many photos to multiple categories, this is the output:
Code:
...
adding photo: 27.jpg to category: category1, total length is now: 27
adding photo: 28.jpg to category: category1, total length is now: 28
adding photo: 29.jpg to category: category1, total length is now: 29
adding photo: 30.jpg to category: category1, total length is now: 30
adding photo: 01.jpg to category: category2, total length is now: 31
adding photo: 02.jpg to category: category2, total length is now: 32
adding photo: 03.jpg to category: category2, total length is now: 33
adding photo: 04.jpg to category: category2, total length is now: 34
adding photo: 05.jpg to category: category2, total length is now: 35
adding photo: 06.jpg to category: category2, total length is now: 36
adding photo: 07.jpg to category: category2, total length is now: 37
	var caption:String;
	
	function photo(fileName:String,caption:String)
	{
		this.fileName = fileName;

...


As you can see, when the category changes, the array length keeps going up. It is almost as if the two arrays for the two different categories are not independent. I don't know what could be causing this, can sombody help me out?

Reply With Quote
  #2  
Old February 3rd, 2004, 07:50 AM
Tann San Tann San is offline
Gotta get to the next screen..
Click here for more information.
 
Join Date: Nov 2003
Location: Legion of Dynamic Discord
Posts: 4,584 Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)  Folding Points: 7835 Folding Title: Novice Folder
Time spent in forums: 3 Weeks 5 h 57 m 29 sec
Reputation Power: 534
Facebook MySpace
Hi, what happens if you re-init the array:
Code:
class photoCategory 
   {
      var name:String;
      var photos_arr:Array = new Array();
      var path:String;
	
      function photoCategory(name:String,path:String)
         {
             this.name = name;
             this.path = path;
             this.photos_arr = new Array();
         }

      function addPhoto(thePhoto : photo)
         {		
             this.photos_arr[this.photos_arr.length] = thePhoto;
             trace("adding photo: "+thePhoto.fileName+" to category: "+name+", total length is now: "+this.photos_arr.length);
         }
   }
__________________
-Tann

-Vote for your favorite ActionScript editor here.

Reply With Quote
  #3  
Old February 6th, 2004, 04:21 PM
blatant's Avatar
blatant blatant is offline
World Domination
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: San Diego
Posts: 126 blatant User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 17 sec
Reputation Power: 6
Send a message via AIM to blatant
Thanks Tann, I changed it to the following and it worked fine:

Code:
class photoCategory 
   {
      var name:String;
      var photos_arr:Array;
      var path:String;
	
      function photoCategory(name:String,path:String)
         {
             this.name = name;
             this.path = path;
             this.photos_arr = new Array();
         }

      function addPhoto(thePhoto : photo)
         {		
             this.photos_arr[this.photos_arr.length] = thePhoto;
             trace("adding photo: "+thePhoto.fileName+" to category: "+name+", total length is now: "+this.photos_arr.length);
         }
   }

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignFlash Help > class problems


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway