ActionScript 3 Flash error 1009 and 2025 combo box - actionscript-3

Im trying to insert a music using combo box from the component asset. yesterday works fine, but today suddenly it stopped working and it gave me this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
everytime I clicked on the combo box these error appears, strangely it works fine yesterday.
this is the code for the first frame:
import flash.events.Event;
import flash.events.MouseEvent;
import flash.system.fscommand;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.events.Event;
import flash.media.SoundTransform;
import flash.events.MouseEvent;
//Declare MUSIC Variables
var musicSelection:Sound;
var musicChannel:SoundChannel;
var musicTrack:String = "music/dearly_beloved.mp3";
var musicVolume:Number=0.2;
/*var isMuted = false;*/
loadMusic();
function loadMusic():void
{
//first stop old sound playing
SoundMixer.stopAll();
musicSelection = new Sound();
musicChannel = new SoundChannel();
//create and load the required soun
musicSelection.load(new URLRequest(musicTrack));
//when loaded - play it
musicSelection.addEventListener(Event.COMPLETE, musicLoaded);
}
function musicLoaded(evt:Event):void
{
//finished with this listener
musicSelection.removeEventListener(Event.COMPLETE, musicLoaded);
//play music
playMusic();
}
function playMusic():void
{
//play the random or selected music
musicChannel = musicSelection.play();
//setting the volume control property to the music channel
musicChannel.soundTransform = new SoundTransform(musicVolume, 0);
//but add this one to make repeats
musicChannel.addEventListener(Event.SOUND_COMPLETE, playAgain);
}
function playAgain(evt:Event):void {
// remove this listener and repeat
musicChannel.removeEventListener(Event.SOUND_COMPLETE, playAgain);
playMusic();
}
and this is the code for the second frame:
import flash.events.Event;
menuBtn.addEventListener(MouseEvent.CLICK, goToMenu)
function goToMenu(evt:Event):void
{
gotoAndPlay(2);
}
// BUTTON EVENT LISTENERS
musicCombo.addEventListener(Event.CHANGE, updateMusic);
volumeSL.addEventListener(Event.CHANGE, setSlider);
//process COMBO BOX changes
function updateMusic(evt:Event):void
{
if (musicCombo.selectedItem.data == "none")
{
//no music is required so stop sound playing
SoundMixer.stopAll();
}
else
{
//otherwise load in the selected music
musicTrack = "music/" + musicCombo.selectedItem.data;
loadMusic();
}
}
function setSlider(evt:Event):void
{
//identify the button clicked
var mySlider:Object = (evt.target);
//adjusting to volume of the music channel
musicVolume = mySlider.value;
musicChannel.soundTransform = new SoundTransform(musicVolume, 0);
}
the error occurs whenever I clicked on the combo box and when I tried to insert another combo box without putting any data, the same error occurs. hope you guys can help me ASAP cause this is due on friday this week xD
thanks

Alright, found the answer. It seems I need to put these 3 lines of code:
import fl.events.ComponentEvent;
import fl.controls.ComboBox;
import fl.data.DataProvider;

Related

ActionScript 3.0 sound not working

So having trouble making sound on keyboard press
I have the imports:
import flash.net.URLRequest;
import flash.media.Sound;
I have the variables
private var soundDownRequest:URLRequest = new URLRequest ("SoundDown.mp3");
private var downSound:Sound = new Sound (soundDownRequest);
and the event listener
private function keyDownHandler(evt:KeyboardEvent):void
{
if (evt.keyCode == 40)//ascii for down arrow
{
downSound.play();
}
}
The sound folder is in the same folder as the .as, its also in the library of the fla, yet it still doesn't work. Any idea why?
Thank you.
Update:
I got the sound to work but not using the external method I was trying to do above.
Had to do it internally.
so you need:
import flash.media.SoundChannel;
-Then you need to make sure your sound file is in your fla library.
once its in the library
-Right click > properties
-Select the Action Script Tab
-Check "export for action script"
-Give the class a name in accordance to the sound
-press ok
add this variable (your will be different):
private var downSound:TheDownSound = new TheDownSound();
downsound is the selected name of the variable, and TheDownSound is the name of the class (the one made earlier for the sound file)
then add this to where you want the sound to play:
var myDownSound:SoundChannel = downSound.play();
Do this if you cant get it working externally like me.
for a better explanation watch this guys youtube video:
https://www.youtube.com/watch?v=SZpwppe7yGs
Your code is working perfectly ok if you put your .mp3 file in the same folder as the output .swf, not near the class .as source file (because its the swf file loading the sound, so the path must be relative to it)
public class ASEntryPoint extends Sprite {
private var soundDownRequest:URLRequest = new URLRequest ("click.mp3");
private var downSound:Sound = new Sound (soundDownRequest);
public function ASEntryPoint() {
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
}
private function keyDownHandler(evt:KeyboardEvent):void{
if (evt.keyCode == 40) {
downSound.play();
}
}
}
You need to load the external file, which is asynchronous operation. Then you track the loading event and if it all goes normally you can play your loaded sound.
import flash.events.SecurityErrorEvent;
import flash.events.IOErrorEvent;
import flash.events.Event;
import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
// Keep the sound loader from being garbage collected.
var soundLoader:Sound;
function loadSound(url:String):void
{
var aRequest:URLRequest = new URLRequest(url);
soundLoader = new Sound();
// Handle the normal loading.
soundLoader.addEventListener(Event.COMPLETE, onLoaded);
// Handle the error cases.
soundLoader.addEventListener(IOErrorEvent.IO_ERROR, onError, false, 0, true);
soundLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError, false, 0, true);
soundLoader.load(aRequest);
}
var audioChannel:SoundChannel;
function onLoaded(e:Event):void
{
// Sound is available here for playback.
audioChannel = soundLoader.play();
}
function onError(e:Event):void
{
trace(e);
}
You can also handle your sound as a streaming audio, but I worked with that years ago in AS2 so I cannot help here. Still, internet suggests a link: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d22.html

try catch issues actionscript3 IOErrorEvent

This is image share app written in as3. in my ftp there is a file "/Images" and images are inside of that. names are 1.jpg 2.jpg 3.jpg until 21.jpg .(21 images inside of folder). as you can see there are 2 variable totalImages and imageNumber. I entered totalImages = 100.
when I click next button its going next page(next image. Starting 1.jpg). But when it comes image 21(last image),if I click next button i cannot pass image 22.(there is no 22.jpg).And I take this error on Output on Flash. Error #2044: Unhandled IOErrorEvent:. text=Error #2036: Load Never Completed. I want to use try catch method and see error inside of swf. but I dont know where i put try and catch in the code. Thank you in advance
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;
//*****************CREATING VARIABLES*****************************//
//the array has all picture labels
//var myGlow:GlowFilter = new GlowFilter(0xffffff,1,10,10,255);// saving the glow
//var myShadow:DropShadowFilter = new DropShadowFilter(6);// saving the shadow to be applied later
var totalImages=100;
var imageNumber=1;
var myLoader:Loader = new Loader();
//************LOADING IMAGES TO STAGE********************//
//elearningau.com/nondynamic/
var myRequest:URLRequest = new URLRequest("http://www.elearningau.com/nondynamic/Images/"+imageNumber+".JPG");
myLoader.load(myRequest);
addChildAt(myLoader,1);// will be added under the buttons layer but over the texture
//************CENTERING THE PICS****************//
myLoader.contentLoaderInfo.addEventListener(Event.INIT, getImageInfo);
function getImageInfo(event:Event){
myLoader.width = 485;
myLoader.height = 360;
var imgX=(stage.stageWidth- myLoader.width)/(-1)*(1/25);
var imgY=(stage.stageHeight- myLoader.height)/2;
myLoader.x=imgX;
myLoader.y = imgY;// lines 37,38,39 & 40 are centering the loader formulae
//myLoader.filters = [myGlow, myShadow];// adding a white color glow / grey shadow
//var myTween:Tween = new Tween(myLoader, "alpha", None.easeNone, 0,1,2,true);//apply fade in
}
//**************GOING TO NEXT IMAGE********************************//
rightButton.addEventListener(MouseEvent.CLICK, nextImage);
function nextImage(event:MouseEvent){
if(imageNumber<totalImages)
{
imageNumber++;
}
else (imageNumber=1);
reload();
}
//**************GOING TO PREVIOUS IMAGE********************************//
leftButton.addEventListener(MouseEvent.CLICK, previousImage);
function previousImage(event:MouseEvent){
if(imageNumber>1)
{
imageNumber--;
}
else (imageNumber=totalImages);
reload();
}
//*****************RELOADING****************************//
//elearningau.com/nondynamic/
function reload(){
removeChild(myLoader);
myRequest= new URLRequest("http://www.elearningau.com/nondynamic/Images/"+imageNumber+".JPG");
myLoader.load(myRequest);
addChildAt(myLoader,1);// will be added under the buttons layer but over the texture
}
You are missing the error handlers from your loader:
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);
function onError(e:IOErrorEvent):void {}
try/catch does not work with asynchronous events, and load is asynchronous.

error access of undefined event

i cant seem to go back to the first frame after the game over screen.
i get the error message Scene 1, 1119: Access of possibly undefined property Event through a reference with static type Class in frame 2 is it because i don't have a classset up in frame 1.
import flash.events.Event;
stop();
var isRight:Boolean=false
var isLeft:Boolean=false
var isUp:Boolean=false
var isDown:Boolean=false
stage.addEventListener(KeyboardEvent.KEY_DOWN, downKey);
function downKey(event:KeyboardEvent)
{
if(event.keyCode==39)
{
isRight=true
}
if(event.keyCode==37)
{
isLeft=true
}
if(event.keyCode==38)
{
isUp=true
}
if(event.keyCode==40)
{
isDown=true
}
}
ect...and the next frame code to go back to the previous one is
import flash.events.Event;
restart.addEventListener(Mouse.Event.MOUSE_UP,click)
function click(e:MouseEvent)
{
gotoAndStop(1);
}
you accidentally wrote Mouse.Event.MOUSE_UP instead of MouseEvent.MOUSE_UP in your addEventListener function

How to delay when my actionscript 3 code runs?

I am creating a drag and drop game that I followed through a Lynda tut. I kept getting an error for my game that I created because I noticed (after weeks of reviewing the code and having other people look at it to figure out what was wrong) that the tutorial that I followed did everything on frame one but I was making my game start at frame 3. So if I start my game at frame 1, it works perfectly and I wont get these errors:
This occurs when I test the movie, once I click continue I am able to see the movie -
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at simpleSpring()[simpleSpring.as:21]
And this occurs when I drag my object -
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at DragDrop/drop()[DragDrop.as:33]
Since I know these errors won't appear unless I begin the game at frame 1, I want to know what code I can place so that I can begin the game at frames that are past the first frame.
The following is the code for DragDrop.as
package
{
import flash.display.*;
import flash.events.*;
public class DragDrop extends Sprite
{
var origX:Number;
var origY:Number;
var target:DisplayObject;
public function DragDrop()
{
// constructor code
origX = x;
origY = y;
addEventListener(MouseEvent.MOUSE_DOWN, drag);
buttonMode = true;
}
function drag(evt:MouseEvent):void
{
stage.addEventListener(MouseEvent.MOUSE_UP, drop);
startDrag();
parent.addChild(this);
}
function drop(evt:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_UP, drop);
stopDrag();
if(hitTestObject(target))
{
visible = false;
target.alpha = 1;
Object(parent).match();
}
x = origX;
y = origY;
}
}
}
And here is the simpleSpring.as
package
{
import flash.display.*;
import flash.events.*;
public class simpleSpring extends MovieClip
{
var dragdrops:Array;
public function simpleSpring()
{
// constructor code
dragdrops = [ladyone,ladytwo,ladythree,ladyfour,ladyfive,ladysix];
var currentObject:DragDrop;
for(var i:uint = 0; i < dragdrops.length; i++)
{
currentObject = dragdrops[i];
currentObject.target = getChildByName(currentObject.name + "_target");
}
}
public function match():void
{
}
}
}
I tried adding the code to a actions layer in the game document but that also does not seem to work correctly.
I am such a newbie when it comes to publishing things. I noticed I can add multiple swf files when I publish for android. This solves my issue of not being able to code at the beginning frame. If I have this game in a separate flash file saved in the same folder with the title movie calling to it with actionscript, the code will work and I am able to publish the whole thing as one file. Thanks again for those that tried to help me figure this out!

ArgumentError: Error #2025 when removeChild

I wrote a AS3 class to make a Counter function. Click and hold mouse in blue area to define a value. I try to show a indicator picture to users that reminding the variation.
But when I drag mouse a little quick in the blue area a error will occur:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at test/get2()
I have read some similar issue posts, but I can't fix this. Could you give me any help? Thank you!
Download .fla and .as in CS6
Download .fla and .as in CS5
The code is below:
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.text.TextFormat;
import flash.events.Event;
public class test extends Sprite{
var i:int=20; //Set a var for the number displayed in stage.
var mx1:Number; //Set a var to save MouseY when MOUSE_DOWN
var mx2:Number; //Set a var to save MouseY when MOUSE_UP
var num:int=0; //Set a var to calculate result
var sub1:subbar1=new subbar1();
var sub2:subbar2=new subbar2();
var sub3:subbar3=new subbar3();
var add1:addbar1=new addbar1();
var add2:addbar2=new addbar2();
var add3:addbar3=new addbar3();
public function test() {
init1(); //Set TextField and addEventListener
initbar(); //Set indicator picture position when drag mouse
}
private function init1():void{
label=new TextField();
label.text=String(i);
label.width=280;
label.selectable=false;
label.x=140;
label.y=90;
addChild(label);
Controler.addEventListener(MouseEvent.MOUSE_DOWN,get1); //addEventListener to bluearea
}
private function initbar(){
sub1.x=sub2.x=sub3.x=add1.x=add2.x=add3.x=30;
sub1.y=35;
sub2.y=55;
add3.y=sub3.y=75;
add2.y=95;
add1.y=115;
}
private function get1(evt:MouseEvent):void{
mx1=mouseY;
trace(mx1);
Controler.removeEventListener(MouseEvent.MOUSE_DOWN,get1);
stage.addEventListener(MouseEvent.MOUSE_UP,get2); //addEventListener to MOUSE_UP
stage.addEventListener(Event.ENTER_FRAME,lifebar); //add ENTER_FRAME to display indicator picture when move mouse
}
private function get2(evt:MouseEvent):void{
mx2=mouseY;
trace(mx2);
if(mx2<=135&&mx2>=35&&mouseX<=130&&mouseX>=50){ //Limited enable area as the blue area
if(num>=4){ //Set i value depends on num
i=i-3;
}else if(num<=-4){
i=i+3;
}else{
i=i-num;
}
label.text=String(i);
}
if(num==1){ //remove indicator picture when MOUSE_UP
removeChild(sub1);
}
if(num==2){
removeChild(sub1);
removeChild(sub2);
}
if(num>=3){
removeChild(sub1);
removeChild(sub2);
removeChild(sub3);
}
if(num==-1){
removeChild(add1);
}
if(num==-2){
removeChild(add1);
removeChild(add2);
}
if(num<=-3){
removeChild(add1);
removeChild(add2);
removeChild(add3);
}
stage.removeEventListener(MouseEvent.MOUSE_UP,get2);
Controler.addEventListener(MouseEvent.MOUSE_DOWN,get1);
stage.removeEventListener(Event.ENTER_FRAME,lifebar);
}
private function lifebar(evt:Event):void{ //Set a ENTER_FRAME to display indicator picture
num=(mouseY-mx1)/12+1;
trace(num);
if(mouseY!=mx1&&num==1){
addChild(sub1);
}
if(num==2){
addChild(sub2);
}
if(num==3){
addChild(sub3);
}
if(num==-1){
addChild(add1);
}
if(num==-2){
addChild(add2);
}
if(num==-3){
addChild(add3);
}
}
}
}
You are attempting to remove display objects that have not yet been added as a child to the display list.
Even though sub1 has been instantiated, it has not been added at the time you attempt to remove it:
Before calling removeChild(obj) on the display object, first test if it has been added as a child by evaluating whether if(contains(obj)) is true.
At line 67 in test.as, you should perform condition testing to see if sub1 has been added to the display list:
if(num==1) {
if(contains(sub1)) // test to see if sub1 is on the display list
removeChild(sub1);
}
If this issue continues with other children, you should add additional testing in blocks like these:
if(num==2){
removeChild(sub1);
removeChild(sub2);
}