Error #1010 at falsh as3 - actionscript-3

i am new to flash, i was created volume slider, and i was clearly created instance for all volume function but it give the follow error
TypeError: Error #1010: A term is undefined and has no properties.
the exact error place in the following code is
bgslider.mc.addEventListener(MouseEvent.MOUSE_DOWN,StartDrag);
my player code is
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
import flash.events.Event;
import flash.geom.Rectangle;
btnstop.addEventListener(MouseEvent.MOUSE_OUT,StopOut);
btnstopo.addEventListener(MouseEvent.MOUSE_OVER,StopOver);
function StopOver(evt:MouseEvent):void
{
btnstopo.visible=false;
btnstop.visible=true;
}
function StopOut(evt:MouseEvent):void
{
btnstop.visible=false;
btnstopo.visible=true;
}
btnplay.addEventListener(MouseEvent.MOUSE_OUT,PlayOut);
btnplayo.addEventListener(MouseEvent.MOUSE_OVER,PlayOver);
function PlayOver(evt:MouseEvent):void
{
btnplayo.visible=false;
btnplay.visible=true;
}
function PlayOut(evt:MouseEvent):void
{
btnplay.visible=false;
btnplayo.visible=true;
}
var soundfile:URLRequest = new URLRequest('http://live32.radio.com:80/;stream1.mp3');
var channel:SoundChannel = new SoundChannel();
var sTransform:SoundTransform = new SoundTransform();
var isplay=1;
var myMusic:Sound = new Sound();
myMusic.load(soundfile);
channel=myMusic.play();
btnplay.addEventListener(MouseEvent.CLICK,PlayRadio);
btnstop.addEventListener(MouseEvent.CLICK,StopRadio);
function PlayRadio(evt:Event):void
{
if(isplay==0)
{
isplay=1;
btnplay.removeEventListener(MouseEvent.MOUSE_OUT,PlayOut);
btnplayo.removeEventListener(MouseEvent.MOUSE_OVER,PlayOver);
btnstop.addEventListener(MouseEvent.MOUSE_OUT,StopOut);
btnstopo.addEventListener(MouseEvent.MOUSE_OVER,StopOver);
SoundMixer.soundTransform = new SoundTransform(1);
btnstop.visible=true;
btnplay.visible=false;
}
}
function StopRadio(evt:Event):void
{
if(isplay==1)
{
btnstop.removeEventListener(MouseEvent.MOUSE_OUT,StopOut);
btnstopo.removeEventListener(MouseEvent.MOUSE_OVER,StopOver);
btnplay.addEventListener(MouseEvent.MOUSE_OUT,PlayOut);
btnplayo.addEventListener(MouseEvent.MOUSE_OVER,PlayOver);
SoundMixer.soundTransform = new SoundTransform(0);
isplay=0;
btnstop.visible=false;
btnplay.visible=true;
}
}
/*var bgslider = new MovieClip();
trace(bgslider.name);
for(var i:uint=0;i<bgslider.numChildren;i++){
trace(bgslider.getChildAt(i).name);
}*/
bgslider.mc.addEventListener(MouseEvent.MOUSE_DOWN,StartDrag);
bgslider.mc.addEventListener(MouseEvent.MOUSE_UP,StopDrag);
function StartDrag(event:MouseEvent):void
{
bgslider.mc.startDrag(true,new Rectangle(152,37,182,0));
}
function StopDrag(event:MouseEvent):void
{
bgslider.mc.stopDrag();
}
please give the correct answer anyone, thanks advance

That TypeError is usually an indication that you misspelled an object reference or didn't give it one at all.
Double check your bgslider and mc reference in the property inspector. Make sure it's not called bg_slider, bgSlider or something like that.

Related

error in my actionscript for a sound slider I'm working on

Hello I' trying to make a sound slider in flash, while working on the code for it; I keep on getting this error Scene 1, 'S Action', Frame 352, line 8 1152: A conflict exists with inherited definition flash.display:MoveClip.isPlaying in namespace public. I'm wondering what I done to cause this error and how can I fix it?
Please get back to me if you can.
stop();
import flash.media.SoundTransform;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
import flash.media.SoundChannel;
var isPlaying:Boolean = true;
var lastPosition:Number = 0;
var mySound:takeachance = new takeachance ;
var myChannel:SoundChannel = new SoundChannel();
var myTransform:SoundTransform = new SoundTransform();
myTransform.volume = .5;
slider02_mc.groove02_mc.scaleX = .5;
myChannel = mySound.play(85,5,myTransform);
myChannel.addEventListener(Event.SOUND_COMPLETE,
soundCompleteHandler);
function soundCompleteHandler(e:Event):void
{
lastPosition=0;
myChannel.stop();
msg_mc.text = "Music stoped playing"
isPlaying = false;
}
play_btn.addEventListener(MouseEvent.CLICK,startSound);
pause_btn.addEventListener(MouseEvent.CLICK,stopSound);
function startSound(myEvent:MouseEvent):void
{
if(!isPlaying)
{
myChannel = mySound.play(lastPosition,5,myTransform);
isPlaying = true;
msg_mc.text="";
myChannel.addEventListener(Event.SOUND_COMPLETE,
soundCompleteHandler);
}
}
function stopSound(myEvent:MouseEvent):void
{
lastPostion = myChannel.position;
myChannel.stop();
isPlaying = false;
}
slider02_mc.mc.addEventListener(MouseEvent.MOUSE_DOWN, myfunction);
function myfunction(event:MouseEvent):void
{
slider02_mc.mc.startDrag(false,new Rectangle(0,0,200,0))
addEventListener(Event.ENTER_FRAME,xpos);
function xpos(event:Event)
{
var myvolume=(slider02_mc.mc.x)/200;
slider02_mc.groove02_mc.scaleX = myvolume;
volume_mc.text = "Volume is"+int(myvolume*100)+"%";
myTransform.volume = myvolume;
myChannel.soundTransform = myTransform;
}
}
stage.addEventListener(MouseEvent.MOUSE_UP,myfunction1);
function myfunction1(event:MouseEvent):void
{
slider02_mc.mc.stopDrag();
addEventListener(Event.ENTER_FRAME,msg);
function msg(event:Event)
{
volume_mc.text="";
}
}
Movieclips already have a property called isPlaying. You should change your variable to something else like soundIsPlaying.

Problems with STAGE

I am pretty new to as3 programming. This forum helped me already a lot, but now I have a problem where I don't know how to get on. So this is my first Post on stack overflow.com.
I need StageWebView for displaying a PDF-document. After several hours, I was successful. I created the code in a new blank document and tested it step by step.
This is my code:
import flash.display.MovieClip;
import flash.media.StageWebView;
import flash.geom.Rectangle;
import flash.filesystem.File;
import flash.display.Sprite;
import flash.display.Stage;
public function StageWebViewExample(pdfdoc:String, xpos:Number, ypos:Number, breite:Number, hoehe:Number)
{
var webView:StageWebView = new StageWebView();
webView.stage = this.stage; //PROBLEM LINE
webView.viewPort = new Rectangle (xpos, ypos, breite, hoehe);
var file:String = pdfdoc;
var pdf:File = File.applicationDirectory.resolvePath(file);
webView.loadURL(pdf.nativePath);
}
StageWebViewExample("test.pdf", 200, 200, 600, 1200);
After testing, I copied the code in my existing flash-document. (The code in a several as-File and the "calling" (StageWebViewExample("....) in the existing flash-document...)
But now the code does't work anymore and there are the following Errors:
- 1119 Access of possibly undefined property stage...
- 1059 Property is read-only.
--> Both Errors referring to the same line I marked in the Code.
Has anyone an idea why it don't work?
I would really appreciate a good hint!
Answer for question is your actions ;) You moved code from the Document Class, in another one, that don't have access to the stage as instance property. I mean this.stage.
Pass Stage also to the method StageWebViewExample, function signature will look like:
public function stageWebViewExample(stage: Stage, pdfdoc:String, xpos:Number, ypos:Number, breite:Number, hoehe:Number):void {
var webView:StageWebView = new StageWebView();
webView.stage = stage;
webView.viewPort = new Rectangle (xpos, ypos, breite, hoehe);
var file:String = pdfdoc;
var pdf:File = File.applicationDirectory.resolvePath(file);
webView.loadURL(pdf.nativePath);
}
Working AIR example:
package {
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.Rectangle;
import flash.media.StageWebView;
public class StackOverflow extends Sprite {
public function StackOverflow() {
addEventListener(Event.ADDED_TO_STAGE, onAdded);
}
private function onAdded(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, onAdded);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
start();
}
private function start():void {
showWebViewAt(this.stage, "http://www.iab.net/media/file/VASTv3.0.pdf", new Rectangle(0, 0, stage.stageWidth * 0.5, stage.stageHeight));
}
private function showWebViewAt(stage:Stage, path:String, frame:Rectangle):void {
var webView:StageWebView = new StageWebView();
webView.stage = stage;
webView.viewPort = frame;
webView.loadURL(path);
}
}
}

Error #1009: Cannot access a property or method of a null object reference

Working on this Flash AS3 application and I am keep getting this error when I try to make an imgLoader clickable.
The imgLoader is a dynamic loader which will load an image from XML file and its created using ActionScript.
This is the full error I get:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at apptest_fla::MainTimeline/frame1()[apptest_fla.MainTimeline::frame1:65]
at runtime::ContentPlayer/loadInitialContent()
at runtime::ContentPlayer/playRawContent()
at runtime::ContentPlayer/playContent()
at runtime::AppRunner/run()
at ADLAppEntry/run()
at global/runtime::ADLEntry()
and this is the code for making the imgLoader clickable:
imgLoader.addEventListener(MouseEvent.CLICK, doSomething);
function doSomething(event:MouseEvent){
nextFrame()
anyone knows why this is happening?
EDIT
This is my entire code:
stop();
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLRequest;
import flash.display.Sprite;
import flash.filters.DropShadowFilter;
var xmlLoader11:URLLoader;
var xml11:XML;
var uRequest11 = new URLRequest("my.xml");
xmlLoader11 = new URLLoader(uRequest11);
xmlLoader11.addEventListener(Event.COMPLETE, onXMLLoad11);
var imgLoader11:Loader;
var nameLoader11:Loader;
var myString11:String = 'loading';
function onXMLLoad11(e:Event) {
xml11 = new XML(e.target.data);
imgLoader11 = new Loader();
imgLoader11.contentLoaderInfo.addEventListener(Event.COMPLETE, onImgLoaded11);
imgLoader11.load(new URLRequest(xml11.Data.Image.text()[0]));
Nametxt11.text = "" + xml11.Data.Name.text()[0];
}
function onImgLoaded11(e:Event) {
addChild(imgLoader11);
imgLoader11.height = 300;
imgLoader11.width = 300;
var bitmapContent11:Bitmap = Bitmap( e.target.content );
bitmapContent11.smoothing = true;
addChild( bitmapContent11 );
bitmapContent11.height = 150;
bitmapContent11.width = 150;
bitmapContent11.y = 65;
bitmapContent11.x = 85;
}
imgLoader11.addEventListener(MouseEvent.CLICK, doSomething);
function doSomething(event:MouseEvent){
nextFrame()
Does it break when this is called:
imgLoader.addEventListener(MouseEvent.CLICK, doSomething);
or when this is called:
nextFrame()
In the first case, imgLoader is null. In the second case, something you're trying to acess fields or methods of right after nextFrame() is called is null.
EDIT:
Try moving this:
imgLoader11.addEventListener(MouseEvent.CLICK, doSomething);
function doSomething(event:MouseEvent){
nextFrame()
}
to the bottom of onXMLLoad11().
function onXMLLoad11(e:Event) {
xml11 = new XML(e.target.data);
imgLoader11 = new Loader();
imgLoader11.contentLoaderInfo.addEventListener(Event.COMPLETE, onImgLoaded11);
imgLoader11.load(new URLRequest(xml11.Data.Image.text()[0]));
Nametxt11.text = "" + xml11.Data.Name.text()[0];
imgLoader11.addEventListener(MouseEvent.CLICK, doSomething);
function doSomething(event:MouseEvent){
nextFrame()
}
}

Error 1119 when creating "Load Text" button

A section of a Flash animation I'm creating involves an area where people can write on a notepad, save their work and update it at a later time. The file will be downloaded by users before they run it, rather than from a webpage. Here is the code I have so far:
import flash.events.MouseEvent;
import flash.net.FileReference;
import flash.display.MovieClip;
import flash.events.Event;
stop();
var MyNotes:FileReference = new FileReference()
Save_btn.addEventListener (MouseEvent.CLICK, SaveText);
function SaveText(Event:MouseEvent):void {
MyNotes.save(TypeOwn_txt.text, "MyNotes.txt");
}
Load_btn.addEventListener (MouseEvent.CLICK, LoadText);
function LoadText(Event:MouseEvent):void {
MyNotes.addEventListener(Event.SELECT, onFileSelected);
var swfTypeFilter:FileFilter = new FileFilter("Text Files","*.txt; .html;*.htm;*.php");
var allTypeFilter:FileFilter = new FileFilter("All Files (*.*)","*.*");
MyNotes.browse([swfTypeFilter, allTypeFilter]);
}
function onFileSelected(event:Event):void
{
trace("onFileSelected");
MyNotes.addEventListener(Event.COMPLETE, onFileLoaded);
MyNotes.load();
}
function onFileLoaded(event:Event):void
{
var fileReference:FileReference=event.target as FileReference;
var data:ByteArray=fileReference["data"];
TypeOwn_txt.text=data.toString();
}
The problem is I receive a "Symbol 'Structure Summary', Layer 'Actions', Frame 29, Line 19 1119: Access of possibly undefined property SELECT through a reference with static type flash.events:MouseEvent.
" in regards to the line "MyNotes.addEventListener(Event.SELECT, onFileSelected);". I've done some research and understand this is something to do with the parent not being identified as a MovieClip, or something along those lines. I'm still not sure, however I don't have a clue how to proceed! Thanks.
Just to let you know the problem is solved, although I really don't know how. I used this site for a template and worked backwards. I'll put in the working Code below in case it's of use to somebody else.
import flash.events.MouseEvent;
import flash.net.FileReference;
import flash.net.FileFilter;
import flash.utils.ByteArray;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.display.MovieClip;
var myNotes:FileReference;
Load_btn.addEventListener(MouseEvent.CLICK, onLoadClicked);
function onLoadClicked(event:MouseEvent):void
{
trace("onBrowse");
myNotes=new FileReference();
myNotes.addEventListener(Event.SELECT, onFileSelected);
var swfTypeFilter:FileFilter = new FileFilter("Text Files","*.txt; *.html;*.htm;*.php");
var allTypeFilter:FileFilter = new FileFilter("All Files (*.*)","*.*");
myNotes.browse([swfTypeFilter, allTypeFilter]);
}
function onFileSelected(event:Event):void
{
trace("onFileSelected");
myNotes.addEventListener(Event.COMPLETE, onFileLoaded);
myNotes.addEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);
myNotes.load();
}
function onFileLoaded(event:Event):void
{
var fileReference:FileReference=event.target as FileReference;
var data:ByteArray=fileReference["data"];
textArea.text=data.toString();
myNotes.removeEventListener(Event.COMPLETE, onFileLoaded);
myNotes.removeEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);
}
function onFileLoadError(event:Event):void
{
myNotes.removeEventListener(Event.COMPLETE, onFileLoaded);
myNotes.removeEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);
trace("File load error");
}
Save_btn.addEventListener (MouseEvent.CLICK, SaveText);
function SaveText(Event:MouseEvent):void {
myNotes=new FileReference();
myNotes.save(textArea.text, "MyNotes.txt");
}
Thanks to everyone who contributed.

Dispatching event doesn't fire :(

package com.fladev.background
{
//import all classes
import caurina.transitions.Tweener;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.display.StageAlign;
import flash.display.StageDisplayState;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.FullScreenEvent;
import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class MainClass extends Sprite
{
//create variables
private var loaderMenu:Loader;
private var loaderNames:Array = new Array ();
private var loaderContents:Array = new Array ();
private var loaderSlide:Loader;
private var swfDisplayObject:DisplayObject;
private var swfComObject:Object;
private var xmlLoader:URLLoader = new URLLoader();
private var xmlSlideLoader:URLLoader = new URLLoader();
public function MainClass()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, stageResize);
xmlLoader.addEventListener(Event.COMPLETE, showXML);
xmlLoader.load(new URLRequest("navigation.xml"));
//xmlSlideLoader.addEventListener(Event.COMPLETE, showSlideXML);
//xmlSlideLoader.load(new URLRequest("slides.xml"));
}
function showXML(e:Event):void
{
XML.ignoreWhitespace = true;
var menuBtns:XML = new XML(e.target.data);
var i:Number = 0;
for ( i = 0; i < menuBtns.navItem.length(); i++ )
{
loaderMenu = new Loader();
loaderMenu.name = menuBtns.navItem[i].name ;
loaderMenu.load(new URLRequest(menuBtns.navItem[i].swfURL));
loaderMenu.contentLoaderInfo.addEventListener(Event.COMPLETE, createSwfObjects);
}
}
private function createSwfObjects(event:Event):void
{
var swfContent = event.currentTarget.content as MovieClip ;
var swfName = event.currentTarget.loader ;
navigationContainer.addChild(event.target.loader);
showImage(swfContent);
if ( swfName.name == 'topNavigation' )
{
swfContent.addEventListener("clickHandle",topNavigationClickHandler);
}
}
private function topNavigationClickHandler():void
{
trace('Back to root');
}
private function showImage(navigationItem):void
{
try
{
navigationItem.alpha = 0;
Tweener.addTween(navigationItem, { alpha:1, time:1, transition:"easeOutSine" } );
navigationItem.smoothing = true;
} catch (e:Error) { trace('Error no tweening'); };
stageResize();
}
private function stageResize(e:Event=null):void
{
var centerImages:Array = new Array ( contentContainer, navigationContainer, backgroundImage ) ;
backgroundImage.x = 0;
backgroundImage.y = 0;
backgroundImage.scaleX = backgroundImage.scaleY = 1;
if ((stage.stageHeight / stage.stageWidth) < backgroundImage.height / backgroundImage.width) {
backgroundImage.width = stage.stageWidth;
backgroundImage.scaleY = backgroundImage.scaleX;
} else {
backgroundImage.height = stage.stageHeight;
backgroundImage.scaleX = backgroundImage.scaleY;
}
for each ( var centered:MovieClip in centerImages )
{
centered.x = stage.stageWidth / 2 - centered.width / 2;
centered.y = stage.stageHeight / 2 - centered.height / 2;
}
}
}
}
This is my code for the main.as.
And here my code for my loaded SWF on the maintimeline.
addEventListener(Event.ADDED_TO_STAGE, init);
function init(event:Event):void
{
trace('try dispatch');
dispatchEvent(new Event("clickHandle",true));
}
Try dispatch works, but it does not get back to the main to fire up "Back to root".
Any idea?
thx!
As long as all movieclips dispatching events are added to the display list, this should work. This makes me think that perhaps the event listener being added is not working. Try adding a trace statement to the block of code as shown below:
if ( swfName.name == 'topNavigation' )
{
trace("adding listener");
swfContent.addEventListener("clickHandle",topNavigationClickHandler);
}
I expect that this if condition is failing, and thus your listener is never being created. Also, you need to add a function parameter to the callback method "topNavigationClickHandler" to accept the event as the callback parameter. You have not done this, and this is an error that would be thrown at runtime when the event was received and dispatched to the callback method. You havn't seen this yet because your listener has never had to invoke the callback. So you're gonna have to fix this code like so:
private function topNavigationClickHandler(e:Event):void
{
trace('Back to root');
}
Also I just want to add that your if condition on setting this listener seems a bit redundant, since you already know you are expecting the navigation swf, because you're explicitly loading it. Also I don't believe the name property would be set like this. Typically the name is only set inside the IDE before compilation, and if it isn't, it gets dynamically generated at runtime. What might be more useful is to check the URL of the loaded SWF to see if it contains "topNavigation" or whatever the swf name is. You can do this like so:
var swfUrl:String = myLoader.contentLoaderInfo.url;
if (swfUrl.search("topNavigation") != -1){
//Match found, add listener for navigation
}