Error in Sample program FlashDevelop - actionscript-3

Here's the code for the sample program, It's a Hello World program.
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
/**
* …
* #author Your Name
*/
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry
var greeting:TextField = new TextField();
}
greeting.text = (“Hello, World”);
greeting.x = 100;
greeting.y = 100;
addChild(greeting);
}
}
When I run it, I get 2 syntax errors, both on line 43 \src\Main.as(43): col: 18 Error: Syntax error. What I'm doing wrong? I googled the problem and no luck, Please Help!!! Any Help would be extremely appreciated!! The link to the tutorial is here "https://precisioncode.wordpress.com/2012/09/16/a-tutorial-in-as3-with-flashdevelop/".

The quotes around “Hello, World” are copy pasted from the web and are not the character you get when you type shift and the quote key, delete the copied ones and type them yourself.

Related

FlashDevelop sound problems

My goal is to create an Asteroids clone, I have the game set, as found on the chrism web tutorial. I have the game almost completely set, but, when I add a sound, The program complains with the following errors.
\src\Main.as(21): col: 3 Error: Access of undefined property soundClip.
\src\Main.as(20): col: 17 Error: Type was not found or was not a compile-time constant: Sound.
The code is shown here :
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
/**
* ...
* #author Chris Moeller
* http://www.chrismweb.com
* Tutorial: Creating an Asteroids Game: Part 4
*/
public class Main extends Sprite
{
[Embed(source = "snd/9mmshot.mp3")]
private const embeddedSound:Class;
var soundClip:Sound = new embeddedSound(); // Bullet
soundClip.play(); // Play the sound
private var game:Game;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
//create the game object passing in the swf width and height
game = new Game(stage.stageWidth, stage.stageHeight);
//add the game bitmap to the screen/ Main.as Sprite to make it visible
addChild(game.bitmap);
//Create the main game loop
addEventListener(Event.ENTER_FRAME, Run);
//add keylisteners
stage.addEventListener(KeyboardEvent.KEY_DOWN, game.KeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, game.KeyUp);
stage.addEventListener(MouseEvent.MOUSE_DOWN, game.MouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, game.MouseUp);
stage.addEventListener(MouseEvent.MOUSE_MOVE, game.MoveMouse);
}
private function Run(e:Event):void
{
game.Update();
game.Render();
}
}
}
I have tried researching the problem and no luck here, I have even checked some adding sound tutorials using the program.
I have even reduced the sound quality as found online
but no luck here and I have no idea what's going on. Please Help!!
Any Help would be extremely appreciated!
I used online audio converter to convert the audio.
To avoid your first error (Error: Type was not found or was not a compile-time constant: Sound.), you have to import the Sound class to your class :
// ...
import flash.media.Sound;
For the second error, you should know that you can not use your soundClip object outside a function, that part is just to declare (and initialize) your objects, so you can do, for example :
private function shotFunction(): void
{
soundClip.play();
}
Hope that can help.

FlashDevelop Errors in Sample program

I'm a beginner to this program, the code is
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
/**
*...
* #author FXDS
*/
public class Main extends Sprite
{
public function Main():Void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry
var greeting:TextField = new TextField();
}
greeting:text = ("Hello World");
greeting.x = 100;
greeting.y = 100;
addChild(greeting);
}
}
However, when I run it, the program complains with the following error :
\src\Main.as(23): col: 17 Error: A constructor cannot specify a return type.
Any Help would be greatly appreciated.
You get that error because you have a little mistake in your code :
public function Main():Void { }
should be
public function Main():void { }
the compiler didn't know Void (with a capital V) which is different from void.
and to avoid that mistake in the future, you can simply write :
public function Main() { }
Hope that can help.

AS3 ArgumentError: Error #1063: Expected 0, got 1

Can anyone can help me with this issue.
I have no idea with this issue.
Just keep getting this issue.
Already try modify from this
function init(e:Event = null) to function init() or function init(e:Event)
Appreciated who can help me with this.
If no issue on this, it should show food not my stage.
package {
import flash.display.MovieClip;
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
import flash.events.Event;
public class Main extends MovieClip {
var snake:Array;
var score:Number;
public function Main() {
// constructor code
if(stage)
addEventListener(Event.ADDED_TO_STAGE, init);
else
init();
}
function init(e:Event = null):void {
//initialize
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
function onEnterFrame(e:Event):void {
var food:Food = new Food();
this.addChild(food);
trace("food");
}
}
}
Your code is almost correct.
Replace if (stage) to if (!stage).
If error still happens attach FLA.

using as3svgrendererlib in flash cs 5.5

I am trying to use http://code.google.com/p/as3svgrendererlib/ in my flash cs 5.5 project to import and load svg files.
I downloaded the swc file from http://code.google.com/p/as3svgrendererlib/downloads/list and linked it in actionscript settings.
I tried compiling the project using the following code:
package {
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.events.Event;
public class Main extends Sprite {
import flash.net.URLLoader;
import flash.net.URLRequest;
//ProcessExecutor.instance.initialize(stage);
public function Main():void {
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = "text";
myLoader.addEventListener(Event.COMPLETE, xmlComplete, false, 0, true);
myLoader.load( new URLRequest("assets/spring_tree_final.svg"));
}
public function xmlComplete(e:Event):void {
trace("it's finished loading");
var svg:SVGDocument = new SVGDocument();
svg.parse(e.target.data);
addChild(svg);
stage.addChild(svg);
}
}
}
But I kept getting the following error:
C:\Users\xx\Desktop\load_svg\Main.as, Line 33 1046: Type was not
found or was not a compile-time constant: SVGDocument.
C:\Users\xx\Desktop\load_svg\Main.as, Line 33 1180: Call to a
possibly undefined method SVGDocument.
So i checked out the source from http://code.google.com/p/as3svgrendererlib/source/checkout and tried importing it using the following line:
import com.lorentz.SVG.*;
right below the 'import flash.events.Event' line.
But I continue to receive the same errors as before.
What am I missing?
You need this import statement:
import com.lorentz.SVG.display.SVGDocument;

Flash TypeError: Error #1009: Cannot access a property or method of a null object reference. - when accessing TLFTextField from Document Class

I'm lost on this one. I receive a TypeError: Error #1009: Cannot access a property or method of a null object reference. output message the first time my Document Class tries to access a simple textfield on the stage (added from the IDE, not actionscript)
package {
import flash.display.*;
import fl.text.*;
import flash.text.*;
import flash.events.*;
import flash.net.*;
public class Main extends MovieClip {
private var _netConnection:NetConnection;
private var _responder:Responder;
/* some other public + private vars */
public function Main() {
init();
}
public function init(e:*=null):void {
_netConnection = new NetConnection();
_responder = new Responder(uponResult);
txt.text = "init()";
}
/* more functions */
}
}
I tried adding txt.addEventListener(Event.ENTER_FRAME, init); incase the txt TLFTextField wasn't ... there... at the beginning, but it still outputs the error.
I feel like a bit of an idiot atm, what's the prognosis doc?
JB
TLFTextFields are weird creatures, I've had a lot of issues with them recently.
I'd try to use the Event.ADDED_TO_STAGE event because the TLFTextFields have to be on the stage when you try to access them:
public function Main() {
addEventListener(Event.ADDED_TO_STAGE, init);
};
public function init(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
txt.text = "init()";
};
It should work if your TLFTextField is on the first frame on the Main Timeline.
Let me know if this one does the magic,
Rob