Okay, so I'm creating a soundboard, and and I've been using Flash for about 2 weeks and Actionscript for about a week, so you'll have to excuse my ignorance. I've used google to look for specific things to no avail so here I am.
Okay, so, I have a soundboard that, when pressing a button, it will hide or show certain buttons on the page, to give the feeling of multiple pages. All my visibility stuff works like a champ.
Right now, in the working version of my soundboard, I'm not using functions to instantiate my linkable objects, create the array, or populate the array to hold the linkable objects.
I would like to use functions to make my code less obtuse. I looked around for a while trying to figure out how to pass an array of objects into a function but i haven't had much success. I'm not quite sure if it's even possible to do. Any ideas on how to improve my code would be greatly appreciated.
These are the errors I get:
1120: Access of undefined property playArraySound001.
1061: Call to a possibly undefined method play through a reference with static type Class.
1120: Access of undefined property playArraySound001.
1120: Access of undefined property GordonSoundArray.
1136: Incorrect number of arguments. Expected 1.
The first code is what works, the next code is the stuff that doesn't work.
This is the working version
Code://////////// CODE FOR PLAYING SOUNDS //// This is creating an instance of the Linkable object var playArraySound001:Link_10_minutes = new Link_10_minutes(); var playArraySound002:Link_3_eggs = new Link_3_eggs(); var playArraySound003:Link_actually_quite_spectacular = new Link_actually_quite_spectacular(); //// Creates a new array var GordonSoundArray:Array = new Array(); //// This is populating an element in a new array with a linkable sound object GordonSoundArray[0]=playArraySound001; GordonSoundArray[1]=playArraySound002; GordonSoundArray[2]=playArraySound003; //// Playing the sound in an array, from an object made Linkable btnTest1.addEventListener(MouseEvent.CLICK, soundtest1); function soundtest1(event_object:MouseEvent):void { GordonSoundArray[0].play(); } btnTest2.addEventListener(MouseEvent.CLICK, soundtest2); function soundtest2(event_object:MouseEvent):void { GordonSoundArray[1].play(); } btnTest3.addEventListener(MouseEvent.CLICK, soundtest3); function soundtest3(event_object:MouseEvent):void { GordonSoundArray[2].play(); } //// All Code Above works and works correctly
this is the version that doesn't work
Code://////////CODE FOR PLAYING SOUNDS //// This is creating an instance of the Linkable object /*var playArraySound001:Link_10_minutes = new Link_10_minutes(); var playArraySound002:Link_3_eggs = new Link_3_eggs(); var playArraySound003:Link_actually_quite_spectacular = new Link_actually_quite_spectacular();*/ //// Creates a new array /*var GordonSoundArray:Array = new Array();*/ //// This is populating an element in a new array with a linkable sound object /*GordonSoundArray[0]=playArraySound001; GordonSoundArray[1]=playArraySound002; GordonSoundArray[2]=playArraySound003;*/ //// Playing the sound in an array, from an object made Linkable /*btnTest1.addEventListener(MouseEvent.CLICK, soundtest1);*/ /*function soundtest1(event_object:MouseEvent):void { GordonSoundArray[0].play(); }*/ /*btnTest2.addEventListener(MouseEvent.CLICK, soundtest2);*/ /*function soundtest2(event_object:MouseEvent):void { GordonSoundArray[1].play(); }*/ /*btnTest3.addEventListener(MouseEvent.CLICK, soundtest3);*/ /*function soundtest3(event_object:MouseEvent):void { GordonSoundArray[2].play(); }*/ //// All Code Above works and works correctly //////////////////////////// Below: Function and Array Testing. ///////////////////////////// ////// Going to Mirror the Above code but make them functions instead //// This is creating an instance of the Linkable object IN A FUNCTION function createInstancesOfLinkableObjects() { //// This is creating an instance of the Linkable object var playArraySound001:Link_10_minutes = new Link_10_minutes(); var playArraySound002:Link_3_eggs = new Link_3_eggs(); var playArraySound003:Link_actually_quite_spectacular = new Link_actually_quite_spectacular(); } //// Creates a new array IN A FUNCTION function createGordonSoundArray():void { var GordonSoundArray:Array = new Array(); } //// This is populating an element in a new array with a linkable sound object IN A FUNCTION function assignLinkagesToArrays():void { //// This is populating an element in a new array with a linkable sound object GordonSoundArray[0]=playArraySound001; //GordonSoundArray[1]=playArraySound002; //GordonSoundArray[2]=playArraySound003; } //// Functions to play the sounds in an array, from the objects made Linkable function soundtest1(event_object:MouseEvent):void { Link_10_minutes.play(); } function soundtest2(event_object:MouseEvent):void { playArraySound001.play(); } function soundtest3(event_object:MouseEvent):void { GordonSoundArray[0].play(); } //// Executing the functions directly without calling them from an event createInstancesOfLinkableObjects(); createGordonSoundArray(); assignLinkagesToArrays(); //// test buttons for the functions to play the sounds btnTest1.addEventListener(MouseEvent.CLICK, soundtest1); btnTest2.addEventListener(MouseEvent.CLICK, soundtest2); btnTest3.addEventListener(MouseEvent.CLICK, soundtest3);



Bookmarks