Alert.Show() null reference as3 - actionscript-3

I simply want to popup an Alertbox in AS3. I am using Flashdevelop and I got the null reference error when I just run this simple code. I THINK that it has something to do with the stage, but I don't know.
import mx.controls.Alert;
public class Main extends Sprite
{
public function Main()
{
Alert.show("hello World","title",Alert.YES | Alert.NO);
}
}
I would like to run this alert and depending what the Alert returns I would love to return a true or false. But I would be glad if we can start with the displaying of the alertdialog

Alert is a flex component. Are you sure you are creating a flex application?

The problem was, that I wrote all my text in the AS files. When I used an MXML file as view, the alert will pop up correctly.

Related

ActionScript3 DataGrid how to display content on browser

Thanks very much for being the most answered community on the web.
I have this small problem:
I want to read a database using Tomcat Servlets into a ActionScript DataGrid.
Please mind that I want it to be pure ActionScript; no mix with MXML.
I have already done a exercise with MXML and DataGrid but it is not meeting my requirement.
I want to understand how to use ActionScript libraries.
thanks for listening
Here is the code:
package {
import flash.display.*;
import spark.components.DataGrid;
import mx.collections.ArrayList;
public class EmpDBDebug extends Sprite {
public var empDG:DataGrid;
public var DGArray:Array = [
{Album:'Slanted and Enchanted'},
{Album:'Brighten the Corners'}];
public var DGArrayList:ArrayList;
public function EmpDBDebug() {
empDG = new DataGrid();
DGArrayList = new ArrayList(DGArray);
empDG.dataProvider = DGArrayList;
addChild(empDG);
}
}
}
This is a simplified version of what I want to do. I have replace Servlet with Array. All I want to do is display the DataGrid content on browser. I am not able to do that. It is refreshing but everything is blank. Hope I am doing something wrong. I tried everything. I replace Sprite with Stage but still nothing works.
Since I want to do it in pure ActionScript without using MXML, are there any other libraries which I should be using. And again I am mostly using Notepad++ and MonsterDebugger. I do not have access to fl.data.DataProvider libraries. Let us rule it for the time being. I am bit confused with Flash Licensing. Can I do it with Apache Flex?
Can you throw some light.
thanks again
RR23850

How do I add MovieClips to the stage while using AIR?

So I had been messing around in AS3 for awhile and had done some basic starting flash game things, but then found out I could use air to make them for mobile platforms. So I tried copying over what I had worked on before, but I am running into issues.
Right now I am just trying to find out how to add an instance of a MovieClip to the stage. I have an image converted to a MovieClip with it's own class so I can manipulate it later (such as moving around) and I have this in my Main class:
class Main extends MovieClip
{
var space:Background; //Background is the MovieClip
function Main():void
{
space = new Background(stage);
stage.addChild(space);
}
}
But when I run the program, the image doesn't show up. It works that way when I just had a standard AS3 program and I don't understand why it would be different when I am trying to use AIR. Any assistance would be greatly appreciated, thank you.
Put the word 'public' in front of 'class' in your first line.
Also remove the 'stage' from the first line in your constructor: make it space = new Background();
And do you really need 'stage' in the addChild statement? Unnecessarily verbose!
I can run this code through the AIR compiler (AIR SDK 3.8 or later):
package
{
import flash.display.MovieClip;
public class MAIN extends MovieClip
{
var space:Background;
public function MAIN()
{
space = new Background();
stage.addChild(space);
}
}
}
With an image inside the Background class it shows up fine. My 'Background' is a library symbol linked for Actionscript. If your 'Background' is pure Actionscript are you adding a graphic to it?
Rajneesh Gaikwad had the answer, I didn't have my Main class as my Document class.

Action script adding a background

First of all I've just a couple hours experience with Flash and AS3 therefore, I'm sorry if it is a bit easy question.
What I want do to is a simple space war games to learn basics of AS3 and flash. Altough I dont know much things about layers, I think my game should contain two layers, one for background and the second one is for enemies spaceships and our spaceship.
I added a jpeg format file to library to use it as a background. (as you can see from the link :http://prntscr.com/2pe6zb and http://prntscr.com/2pe733 )
And I create a as3 documentFile which is called Arkaplan.as and content of it is:
package{
import flash .display.*;
public class Arkaplan extends MovieClip{
public function Arkaplan(){
var hero:backGround =new backGround();
addChild(hero);
}
}
}
However, I got an error which says that : "1180: Call to a possibly undefined method BackGround."
Is there anyone to help me to solve what is wrong ?
EDIT
When I changed the code above lilke :
package{
import flash .display.*;
public class Arkaplan extends MovieClip{
public function Arkaplan(){
var myBitmap:Bitmap = new Bitmap(new backGround(500, 500));
var myMovieclip:MovieClip=new MovieClip();
myMovieclip.addChild(myBitmap);
addChild(myMovieclip);
trace("deneme 1-2");
}
}
}
Problem is solved but I dont know why it runs correctly know ? To be able to use Bitmap Do I have to add it as a child to movieClip ?
Any time you use the word 'new' you are creating a new object. The word after new will be the name of a Class that Flash will try to locate. You must either have an external .as file that matches that name or have a library item set to 'export for ActionScript' with a Class name that matches that name.
You can access a library item's properties by right-clicking on it in the library and clicking 'properties'. With the 'advanced' option open, check the 'export for ActionScript' box and enter a Class name that matches the one you want to create.

How to extend class that is inside a loaded swf

I've got an swf loaded externally to my app with loader component. It is loaded to the Application Domain of my loader. I've got a class in that swf wich I would like to extend and override some functions from it. Is it possible somehow?
Here is some code to explain what I want(of course, it is fully incorrect and wold not work):
public var ClassFromLoadedSwf:Class = ApplicationDomain.currentDomain.getDefinition("path.to.needed.class") as Class;
public class MyClass extends ClassFromLoadedSwf
{
override protected function initMovie() : void
{
//function logic goes here
}
}
Thank you for your answers and sorry for my bad english.
No you can't. Basically you don't understand the meaning of ApplicationDomain. Using a loader and Applicaiton Domain you just merge some code to your SWF in Runtime. Before it reaches the Runtime state, it can't be accessed. So at the Compile time you can't do what you're trying to do now. But you can try to use SWC instead of SWF. You just include it in your Project Library and that's all. You'll be able to access all the classes at compile time. Try reading this Article. It will help you understand the meaning of SWCs.

1119:Access of possibly undefined property Click through a reference with static type Class

I am making an edutainment game using flash cs5, I'm really new at using flash, in fact we never yet tackle it at school, but I insist on learning about it.
In my codes, I encountered this error
C:\Users\acer\Desktop\JikanLibrary\Main.as, Line 16 1119: Access of possibly undefined property Click through a reference with static type Class.
This is the code I used in my program
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Main extends MovieClip
{
var startPage:StartPage;
var jikanBookshelf:JikanBookshelf;
public function Main()
{
startPage = new StartPage;
jikanBookshelf = new JikanBookshelf;
startPage.jikanBookshelf.addEventListener(MouseEvent.Click, onJikanBookshelf);
addChild(startPage);
function onJikanBookshelf(event:MouseEvent):void
{
addChild(jikanBookshelf);
removeChild(startPage);
}
}
}
}
The error is in this line
startPage.jikanBookshelf.addEventListener(MouseEvent.Click, onJikanBookshelf);
Since I'm really new at flash, I really don't know what went wrong with my codes, it was working a while ago before I put the mouse event. I hope someone could help me.
ActionScript is a case sensitive language. This means that Click is not the same as CLICK. So what you need here is MouseEvent.CLICK
"Why is CLICK all uppercase? Most property names aren't.", you might ask.
That's because CLICK is a static constant property of MouseEvent and the convention amongst ActionScript (and many other languages) programmers is that static constants are written in all uppercase to distinguish them visually from other variables.
'static' means it's a property of the MouseEvent class, not of an instance of MouseEvent.
'const' means it's not a variable: you can't change it's value.
It's a name conflict problem: The class definition name is same as the object name.
The problem in your script is that you have a class definition name startPage and you are trying to create an object of same name startPage.
You have to change the object name to something different. Let say startpage1.