PDA

View Full Version : how can i communicate between classes?


Lazer57
11-20-2007, 10:22 PM
I have a class that plays a sound. I have another class that moves the timeline one frame. I would like the class that plays a sound to use the other class to move the timeline one frame. The code that I have gives me an error. Below is the error and the two classes. Thanks ahead of time for any responses.

Error:
1136: Incorrect number of arguments. Expected 1.

SoundMove.as:
package lesson
{
import flash.display.DisplayObjectContainer;

public class SoundMove extends DisplayObjectContainer
{
public function SoundMove()
{
MovieClip(DisplayObjectContainer(root)).gotoAndPla y(MovieClip(DisplayObjectContainer(root)).currentF rame + 1);
}
}
}

SoundMain.as:
package lesson
{
import flash.events.*;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.media.SoundMixer;

public class SoundMain extends Sound
{
private var micURL:String = "micRec1.mp3";
private var song:SoundChannel;

public function SoundMain()
{
var rqst:URLRequest = new URLRequest(micURL);
var soundFactory:Sound = new Sound();
soundFactory.addEventListener(Event.COMPLETE, completeHandler);
soundFactory.addEventListener(Event.ID3, id3Handler);
soundFactory.addEventListener(IOErrorEvent.IO_ERRO R, ioErrorHandler);
soundFactory.addEventListener(ProgressEvent.PROGRE SS, progressHandler);
soundFactory.load(rqst);
song = soundFactory.play();
}

private function completeHandler(event:Event):void
{
trace("completeHandler: " + event);
SoundMove();
}

private function id3Handler(event:Event):void
{
trace("id3Handler: " + event);
}

private function ioErrorHandler(event:Event):void
{
trace("ioErrorHandler: " + event);
}

private function progressHandler(event:ProgressEvent):void
{
trace("progressHandler: " + event);
}
}
}

Lazer57
11-21-2007, 12:29 AM
I changed SoundMove(); to var sndMove:SoundMove = new SoundMove(); and the swf played fine, the sound played but I got an error that wouldn't allow the timeline to move forward a frame. Below is the error, I would appreciate any help.

ArgumentError: Error #2012: SoundMove class cannot be instantiated.
at lesson::SoundMain/::completeHandler()

Flash Gordon
11-21-2007, 02:22 AM
I can't see your SoundMove class so I don't know what it want instantiate. Also, if you'd post the complete error to the first problem it would be a lot simpler to trouble shoot.

Ryratt
11-21-2007, 03:42 AM
I changed SoundMove(); to var sndMove:SoundMove = new SoundMove(); and the swf played fine, the sound played but I got an error that wouldn't allow the timeline to move forward a frame. Below is the error, I would appreciate any help.

ArgumentError: Error #2012: SoundMove class cannot be instantiated.
at lesson::SoundMain/::completeHandler()

It's saying you can't make classes/objects out of DisplayObjectContainer since it's an abstract class. Not sure how you'd extend or implement it. I don't think you need it for your purposea though. try
public class SoundMove extends DisplayObject

or

public class SoundMove extends Sprite

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html

amitforum
11-21-2007, 10:25 AM
I have a class that plays a sound. I have another class that moves the timeline one frame. I would like the class that plays a sound to use the other class to move the timeline one frame. The code that I have gives me an error. Below is the error and the two classes. Thanks ahead of time for any responses.

Error:
1136: Incorrect number of arguments. Expected 1.

SoundMove.as:
package lesson
{
import flash.display.DisplayObjectContainer;

public class SoundMove extends DisplayObjectContainer
{
public function SoundMove()
{
MovieClip(DisplayObjectContainer(root)).gotoAndPla y(MovieClip(DisplayObjectContainer(root)).currentF rame + 1);
}
}
}

SoundMain.as:
package lesson
{
import flash.events.*;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.media.SoundMixer;

public class SoundMain extends Sound
{
private var micURL:String = "micRec1.mp3";
private var song:SoundChannel;

public function SoundMain()
{
var rqst:URLRequest = new URLRequest(micURL);
var soundFactory:Sound = new Sound();
soundFactory.addEventListener(Event.COMPLETE, completeHandler);
soundFactory.addEventListener(Event.ID3, id3Handler);
soundFactory.addEventListener(IOErrorEvent.IO_ERRO R, ioErrorHandler);
soundFactory.addEventListener(ProgressEvent.PROGRE SS, progressHandler);
soundFactory.load(rqst);
song = soundFactory.play();
}

private function completeHandler(event:Event):void
{
trace("completeHandler: " + event);
SoundMove();
}

private function id3Handler(event:Event):void
{
trace("id3Handler: " + event);
}

private function ioErrorHandler(event:Event):void
{
trace("ioErrorHandler: " + event);
}

private function progressHandler(event:ProgressEvent):void
{
trace("progressHandler: " + event);
}
}
}
if possible
can u give me your flash files with all as files. i want to chake total condition of your file and structure. i think it's not a big problem
thanks ...

Lazer57
11-21-2007, 04:50 PM
I can't see your SoundMove class so I don't know what it want instantiate. Also, if you'd post the complete error to the first problem it would be a lot simpler to trouble shoot.

I pasted the entire code of the SoundMove class in my first post. I'll repaste it here again for you. Also below is the complete error of the initial setup, but I am not sure it is useful information because I got past that as noted in my second post.

error of initial setup (1st post):
SoundMain.as, Line 28 | 1136: Incorrect number of arguments. Expected 1. | SoundMove();

SoundMove.as
package lesson
{
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;

public class SoundMove extends DisplayObjectContainer
{
public function SoundMove()
{
MovieClip(DisplayObjectContainer(root)).gotoAndPla y(MovieClip(DisplayObjectContainer(root)).currentF rame + 1);
}
}
}

At first I tried to include that whole MovieClip line directly into the completeHandler function of the SoundMain class but it gave me the problem of having to extend two different things, and in another forum I was previously told I should seperate such things to avoid the problem or I could use a work around but it was too difficult for me.

Lazer57
11-21-2007, 04:55 PM
It's saying you can't make classes/objects out of DisplayObjectContainer since it's an abstract class. Not sure how you'd extend or implement it. I don't think you need it for your purposea though. try
public class SoundMove extends DisplayObject

or

public class SoundMove extends Sprite

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html

I imported and extended DisplayObject and I get the same error:

ArgumentError: Error #2012: SoundMove class cannot be instantiated.
at lesson::SoundMain/::completeHandler()

Then I tried importing and extending Sprite and I got a different error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at lesson::SoundMove$iinit()
at lesson::SoundMain/::completeHandler()

Lazer57
11-21-2007, 05:04 PM
if possible
can u give me your flash files with all as files. i want to chake total condition of your file and structure. i think it's not a big problem
thanks ...

It is over 2 megs so I can't attach it via this forums attachment options. So instead I have uploaded it to sendspace. Just click the link and go down, click the link for downloading, you don't have to sign up or anything.

http://www.sendspace.com/file/urjvv1

A little background on it. I am a teacher and I am learning flash and as3 so that I can make flash lessons, so what you see there is my early attempts at making a lesson. Just trying to get the framework of a typical lesson done so I can start making lessons for a variety of topics.

Flash Gordon
11-21-2007, 06:17 PM
yea, it has already been said you can't extend DisplayObjectContainer. I beleive you have to sub class at least Sprite to do it.

Lazer57
11-21-2007, 06:26 PM
yea, it has already been said you can't extend DisplayObjectContainer. I beleive you have to sub class at least Sprite to do it.

Yea I changed it to Sprite and I still get an error. As mentioned in the post to Ryratt, the error I get now is:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at lesson::SoundMove$iinit()
at lesson::SoundMain/::completeHandler()

Flash Gordon
11-21-2007, 06:49 PM
that's a different issue. Somewhere in your code an object is doesn't have a value (which you think it probably does). The error is saying this.

trace( null.property);

because a null object has no properties you can't access any properties of null objects. Make sense? So trace all your objects to see their values.

Lazer57
11-21-2007, 07:17 PM
that's a different issue. Somewhere in your code an object is doesn't have a value (which you think it probably does). The error is saying this.

trace( null.property);

because a null object has no properties you can't access any properties of null objects. Make sense? So trace all your objects to see their values.

Truthfully, I am not sure how to do that. I did try tracing a few things and when I did trace(sndMove); it did return null but only after I added var sndMove:SoundMove; to the constructor. Before I added that it returned ReferenceError: Error #1065: Variable sndMove is not defined. So how can I make it no longer null and call it from within the completeHandler function?

I am guessing I need to add var sndMove:SoundMove = new SoundMove(); to the constructor, but then I don't know how to properly access sndMove in the completeHandler function. If I leave that also in the function then I get an error and the sound doesn't play, which makes sense since I am doing it twice, I guess.

EDIT:
Actually I added var sndMove:SoundMove = new SoundMove(); and then I tried to trace(sndMove); and I got TypeError: Error #1009: Cannot access a property or method of a null object reference. I imported the SoundMove class into the SoundMain class and does same thing. I am a blind man stumbling in the dark, double screwed.

Lazer57
11-22-2007, 03:59 PM
Any more help? I don't think I can solve this problem on my own, at least not anytime soon. I barely got down some basics on how to make classes work, getting them to work together is still a mystery to me.

Mazoonist
11-22-2007, 07:15 PM
I am working on it, as time permits today.

One thing I discovered is that you are attempting to play the sound before it's loaded. I changed that and eliminated that error message. I'll let you know more later on.

Mazoonist
11-22-2007, 07:28 PM
I don't understand what you want to have happen, and when. I assume that you want the main fla to use SoundMain to play a sound clip, then the SoundMove class causes the main timeline to advance to the next frame? But I haven't yet figured out exactly what is supposed to trigger the advance? A click on the 'next' button?

Lazer57
11-22-2007, 08:28 PM
I have uploaded a newer one, made a few changes. Here it is:

http://www.sendspace.com/file/jd8xft

The next button allows students to move forward frames (i may change it to frame labels) so that they can skip certain parts. The SoundMain class plays the sound, does the sound channel and the other stuff having to do with sound. It also has event listeners; I want the completeHandler function to instantiate/activate/whatever the SoundMove class which will move the frame forward. That way when the sound is done, the frame will automatically move forward, that way I can teach frame by frame and it will move fluidly. If I could access the function in the NextButton class to move the frame forward when the sound was done then I could do without the SoundMove class.

Mazoonist
11-22-2007, 08:33 PM
I'll work on your new version later on when I get home from Thanksgiving dinner. Thanks for replying to my PM. Hope you're having a great day. I'm pretty sure I can help you out with your project.

Mazoonist
11-23-2007, 02:50 PM
Lazer57, I worked over your files. Look for a PM from me. I would like to email you the result. As you know, it's too big to attach here.

Lazer57
11-23-2007, 03:22 PM
Lazer57, I worked over your files. Look for a PM from me. I would like to email you the result. As you know, it's too big to attach here.

Yup got your message and replied with my email address. Thanks again, I really appreciate it. It has been really slow going; I had hoped I would have completed a whole lesson by now but I still got a ways to go. Once I get one lesson exactly how I want it I can start pumping out lessons daily.

I really didn't expect for anyone to help that much. Thanks a lot.