Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-09-2009, 03:07 AM   #1
Plarx
Registered User
 
Join Date: Jun 2009
Posts: 5
Question [AS3] Making All Objects in an array invisible

Ive got a flash game in AS3 which the aim of the game is to catch the students that fall asleep by simply clicking on them.
The problem i have is that in my Output window im getting
Quote:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at ClassroomChaos_fla::MainTimeline/asleepHide()
The for loop below is my attempt at hiding all the objects in the asleepArray array. I'll also upload my FLA for you to get a better understanding of what i'm trying to do...


Code:
function asleepHide(evt:Event):void {
	for (var i:uint=0; i < asleepArray.length; i++) {
	trace("im here i++")
		asleepArray[i].visible=false;
		trace("Asleep Students Hidden")
		}
}

Another Problem im having is that the score starts at 1 instead of 0, and my score also increases everytime i click the mouse, not just when i click on a student.

Any help would be greatly appreciated.
Thank you all.


EDIT: Thanks for moving this
EDIT2: Ive found the problem with the for Loop....and it seems that the variable 'i' is not incrementing. I have coded it in another smaller file, and it works fine, so im guessing it is having a conflict with another part of my AS3 code.
This is really starting to annoy me
Attached Files
File Type: zip Classroom Chaos.zip (278.6 KB, 197 views)

Last edited by Plarx; 08-11-2009 at 12:34 PM. Reason: uploading .fla
Plarx is offline   Reply With Quote
Old 08-12-2009, 11:47 AM   #2
Plarx
Registered User
 
Join Date: Jun 2009
Posts: 5
Default

OK People,
I have fixed the problem finally. Now im just having troubles making the asleep students appear in a random position.
This is the code im trying make...

Code:
function studentShow(evt:Event):void {
	timeSinceStudent++;
	if (timeSinceStudent>appearTime) {
		studentArray[studentPos].visible=false;
		asleepArray[studentPos].visible=true;
		timeSinceStudent=0;
	}
}
I might not have the code in my .fla to call the function but when i did have it, it said that: studentShow(); had the "incorrect number of arguments. expected 1"
Attached Files
File Type: zip Classroom Chaos.zip (185.0 KB, 108 views)
Plarx is offline   Reply With Quote
Old 08-12-2009, 04:04 PM   #3
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,982
Default

See the part where it says evt:Event ? That defines the arguments that the function expects.

Code:
If you had defined it as
function studentShow():void {
you could call it as studentShow()
but the use of an Event argument suggests you need it to work with an event listener, right?
Since the evt isn't actually being used, I guess you could get away with calling it with
studentShow(null);
but some people will frown at me for bad practice.  To appease them, you could define two functions, one for each purpose, like so:
function studentShowEvent(evt:Event):void {
	studentShow();
}
function studentShow():void {
	timeSinceStudent++;
	if (timeSinceStudent>appearTime) {
		studentArray[studentPos].visible=false;
		asleepArray[studentPos].visible=true;
		timeSinceStudent=0;
	}
}
rrh is offline   Reply With Quote
Old 08-13-2009, 11:39 AM   #4
Plarx
Registered User
 
Join Date: Jun 2009
Posts: 5
Default

OK thanks for the help.
Ive done a little bit more code and managed to get all the students to fall asleep randomly but right now when I click on a specific student that has fallen asleep, all of the asleep students wake up. I guess this kind of makes sense as the teacher would yell something out and cause any student that is asleep to wake up....

But is there any way to get ONLY the student who is asleep to wake up?
My FLA is attached.
Thank you
Attached Files
File Type: zip Classroom Chaos - Copy.zip (272.4 KB, 82 views)
Plarx is offline   Reply With Quote
Old 08-13-2009, 06:54 PM   #5
snickelfritz
Senior Member
 
Join Date: Jun 2008
Posts: 1,206
Default

Download TweenGroup and place the downloaded "gs" folder in your custom classes directory.
The gs directory contains TweenMax, TweenLite and TweenGroup classes as well as some asing classes and some helper applications (SWF files) to get you started.

Hide all references in an array:
ActionScript Code:
import gs.*; TweenGroup.allTo(asleepArray, .5, {autoAlpha:0});
snickelfritz is offline   Reply With Quote
Old 08-14-2009, 02:24 AM   #6
Plarx
Registered User
 
Join Date: Jun 2009
Posts: 5
Default

thanks for the reply, but im only alowed to use Straight AS3 without any forms of addons or anything else....that woulda been easy but as its for a school project, i have to follow the guidelines
Plarx 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


All times are GMT. The time now is 12: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.