Hello,
I have two movie clips on the stage at frame 1 and frame 2. Both are instances of seperate classes. (They are not dynamically created, just their linkage is set to their class names)
I have created soundChannel and Sound Objects in Class 1 and I want to access them from Class 2. (I want to stop the sound channel that was started in class 1)
Is there any way to do this? If yes, will this be true for other properties also?
Thanking You,
Chinmaya
Accessing Another Class's Properties...Yes, It is possible also with other properties.
You have to have a class design with following conditions:
- Class1 should have access to Class2.
- Class to should have property defined in it, with ''public'' access modifier.
- Instance of Class2 should not be ''null'' while accessing the property.
- Then in Class1 you can say %26lt;Class2Instance%26gt;.%26lt;propertyname%26gt; to access the property.
Thanks for the reply.
I have tried this before, but, the problem, according to me is that I have two instances of two different classes on two seperate frames.
I have a ''public var musicChannel:SoundChannel=new SoundChannel()'' in the instance of class 1 (neither of the class instances are created dynamically as mentioned in first post)
The movie clip instance of the class is named ''UFO1'' (not using the ''.name'' but directly on the stage itself)
I have tried using ''UFO1.musicChannel.stop()'' in Class 2 whose instance is on the next frame.
RESULT : 1120: Access of undefined property UFO1.
Can this be solved?
Chinmaya
Make UFO1 available on the frame where you are calling ''UFO1.musicChannel.stop()''
Also if you don't want it to be there write on the same frame ''UFO1.visible = false''
I guess this will solve your problem...
If that doesn't post the FLA as ZIp here I will give you the solution.
I added the ''UFO1'' on the frame which I want the sound to stop. I was initially having problems in stopping the constructor from running but I managed to stop it using a currentScene check. Now, I am able to access the soundChannel property of the UFO1 Movie Clip. But, even if I type:
UFO1.musicChannel.stop()
It does not stop the sound.
I wont be able to Attach the fla as it is well over 30MB, even though the swf is only 800KB. Is there any other way to solve the problem?
Thanks once more,
Chinmaya
You want to stop the Sound from previous movieclip, right?
you can do this using SoundMixer.stopAll();
It?will stop all the Sounds in your SWF. You can also start any Sound later.
The second approach is make your ''musicChannel'' a global variable.
To do this declare it on a new layer which is blank and avialbale throughout the life of main time line and no keyframes are there [except the first frme].
now to access this variable you can use a statement like below:
(stage as MovieClip).musicChannel.stop();
If that also do not solve your problem then paste the code for both the classes I will look into it.
For now, I have used the stopAll() method from SoundMixer Class. I'll also try using a global variable also and post the results. This is my main problem in flash. I have difficulty in accessing code from different places. If I have written code in a class, then I cant access it from the timeline and vica-versa. I'll surely do a more deep study into this topic. IF I have any problems, I'll post them.
Thank You,
Chinmaya
Your welcome !
No comments:
Post a Comment