Unable to call windows and dialogs from MainWindow - monodevelop

I've added a new window to the solution (Add -> new window)
to start it I wrote:
Wndw1 w = new Wndow1 ();
w.Show ();
But it gives an error
/home/spam/del2/del2/jhj.cs(3,3): Error CS0246: The type or namespace name `Wndw1' could not be found. Are you missing `del2' using directive? (CS0246) (del2)
Even though, the code works in any class other than MainWindow

When You create a new gtk# project, main window will appear automatically
when you create a class later it will be in the namespace, while mainwindow won't
so..add a namespace!

Related

Error #1056: Cannot create property *** on ***

I have a weird problem, and I don't know why this is happening.
I have a movieClip with the name of wellcomeMenu. It is exported for AS with the name of WellcomeMenu, and in the document class I do this:
public var _welcome:WellcomeMenu = new WellcomeMenu();
public function MainTest()
{
_welcome.x = stage.stageWidth * 0.5
_welcome.y = stage.y
addChild(_welcome);
}
All simple stuff. Then I go into the WellcomeMenu movieClip and make a shape with the name Box, then I make it a movieClip too, and give its Instance Name the name specialItem.
To sum up: I dynamically call a wellcomeMenu movieclip, which contains another movieClip with an instance name of specialItem. Then I compile and get this error:
ReferenceError: Error #1056: Cannot create property specialItem on WellcomeMenu.
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at WellcomeMenu()
at MainTest()
what am I doing wrong?
When I remove its instance name, it shows just fine, but I can't manipulate the movieclip within the WellcomeMenu.
I think the problem is in specialItem attribute in the WellcomeMenu class (by the way, you may have an extra l in there if it's English). If the environment is failing to create the attribute, it is probably already there, but with the wrong permission.
If you declared specialItem manually, make sure it's public and not private (public Sprite specialItem) or else the environment won't have permission to set its value.
Another possible issue is that you declared specialItem manually and still enabled the "automatically declare instance", the environment may try to redeclare the attribute and fail. So either remove the manual declaration or disable that option.
The error can happen if you assign an object of one type to another.
var square:Square = new Square();
square.row = 9; //OK, There is a row property in the Square class
var block:Block = new Block();
square = block; //this is not a compiler error, but probably a mistake
square.row = 0; //error if there is no row property on Block

As3 imported custom class won't access components at main stage

I have this situation. I was building all in code, but it's a little painful, so I made a interface with components using the Flash drawing capabilities.
I got a main class, as usual, with the interface in a MovieClip instance called "AreaEdit". In my custom class "EditorHTML" there is a Sprite:
private var dTela:Sprite;
So the constructor is like this:
public function EditorHTML(instEdit) {
this.Parags = new Array();
this.dTela = instEdit;
trace("dTela: "+this.dTela.width+" x "+this.dTela.height);
}
At the main class:
Escrit = new EditorHTML(AreaEdit);
So trace displays the dimensions of the box, as expected. However, at the custom class, if I try to access an instance inside like this:
this.dTela.cxEdit.addEventListener(Event.CHANGE, atualizar);
An error is returned: /Library/WebServer/Documents/as3/bibliotecas_externas/com/gustavopi/txt/EditorHTML.as, Line 49 1119: Access of possibly undefined property cxEdit through a reference with static type flash.display:Sprite.
I did a test and the same instance "cxEdit" is available in main class. So it seams the components instances are not available for a custom class. How do I solve this?
Try to call it like this:
Sprite( Sprite(this.dTela).getChildByName("cxEdit")).addEventListener(Event.CHANGE, atualizar);
In case that cxEdit is a Sprite too.
Edited: cxEdit must be a TextArea. So it can be done like this:
var cxEdit:TextArea = TextArea(Sprite(this.dTela).getChildByName("cxEdit"));
cxEdit.addEventListener(Event.CHANGE, atualizar);
To make it easier for the rest of the code...
From what I can see, you are trying to access the "cxEdit" as a property of Sprite (dTela), which is not a Sprite property, hence the error.
Could you perhaps pass in AreaEdit.cxEdit as the argument instead of just AreaEdit?

AS3/Flex - persistNavigatorState + objects with ArrayCollection()

I currently have a mobile application on the playbook that has the following class:
[Bindable]
public class Foo
{
public var myString:String;
public var myList:ArrayCollection;
public function Foo() {}
}
I also have persistNavigatorState="true" in my ViewNavigatorApplication.
Suppose in my first view I have the following in my creationComplete="init()" call:
private function init():void {
var s:String = "test_string";
var a:ArrayCollection = new ArrayCollection();
a.addItem("test1");
a.addItem("test2");
a.addItem("test3");
data.foo = new Foo();
data.foo.myString = s;
data.foo.myList = a;
trace(data.foo.myString);
trace(data.foo.myList[0]);
trace(data.foo.myList[1]);
trace(data.foo.myList[2]);
}
When executed, everything works fine in my app. However, since I want the sessions to persist in case the user accidentally closes the app, when he re-opens it the data should still be there.
Instead, when I close and re-open my app only the myString property persists (ie traces "test_string", as intended), however the ArrayCollection isn't copied.
I've tried the following with ObjectUtil.clone() and ObjectUtil.copy():
data.foo.myString = ObjectUtil.copy(s) as String;
data.foo.myList = ObjectUtil.copy(a) as ArrayCollection;
and I've also tried:
var f:Foo = new Foo();
f.myString = s;
f.myList = a;
data.foo = ObjectUtil.copy(f) as Foo;
trace(data.foo.myString);
trace(data.foo.myList[0]);
but this only throws me a
TypeError: Error #1009: Cannot access a property or method of a null object reference.
Any ideas on how to persist ArrayCollections and Foo class in a mobile application?
I'm not 100% sure, but I was wondering about this type of problem while working on a mobile app recently.
I believe your problem might be happening b/c your are setting the data manually on the View, instead of passing it into the View with the ViewNavigator.pushView() method.
I just browsed through the source, and it looks like setting the data directly on the View will bypass ViewNavigator's data persistence. Though with that said, I'm not sure why it would even remember the value for that String :)
I would try to do the following:
don't set the View's data property from inside the view, as you are doing now in the creationComplete handler
if possible, use the "firstView" property of ViewNavigatorApplication in mxml
if possible, initialize the "firstViewData" property in mxml (may not be possible)
if you can't do the two above, in your application's startup code call navigator.pushView(View_Class_Name, foo) to pass in the data.

Trying to connect to AMFPHP - NetConnection.connect() returns TypeError: Error #1009

UPDATE: Now I've moved the AMFConnection var declaration to outside the functions in Main, and commented out some trace() commands, and now it gives new errors:
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.BadVersion
at AMFConnection/init()[/Users/Jan/Downloads/amfphp1/AMFConnection.as:32]
at AMFConnection()[/Users/Jan/Downloads/amfphp1/AMFConnection.as:23]
at Main/testConnection()[/Users/Jan/Downloads/amfphp1/Main.as:14]
at Main()[/Users/Jan/Downloads/amfphp1/Main.as:10]
All of these essentially point to AMFConnection's NetConnection initialisation: _netConnection = new NetConnection(); (where _netConnection is declared at the beginning of the class)
I'm trying to connect to AMFPHP on a server (with Flash AS3), and the swf borks when it reaches the .connect() stage. To make things easier (?) and more reusable (?), I've put all the NetConnection mechanics into a separate class, AMFConnection, which I call from the Main document class like this (details changed):
public function testConnection(e:*=null):void {
var conn:AMFConnection = new AMFConnection();
conn.table = "some_table";
conn.selections = "*";
conn.conditionals = "WHERE something = 'something'";
conn.service = "QueryAMF";
conn.method = "makeQuery";
conn.displayText = txt;
conn.gogogo("http://www.someplace.com/Amfphp");
}
AMFConnection actually starts the connection and calls the AMFPHP service with the function gogogo(), and here's where the connect() NetConnection function just won't work. Here's the main section of the AMFConncection class
private var _netConnection:NetConnection;
private var _responder:Responder;
function AMFConnection()
{
init();
}
private function init(e:* = null)
{
_netConnection = new NetConnection();
_responder = new Responder(uponResult);
}
public function gogogo(url:String):void {
trace(url);
_netConnection.connect(url);
_netConnection.call(String(service+"/"+method), new Responder(onResult, null), table, selections, conditionals);
}
A quick debug session reveals the below errors:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AMFConnection/gogogo()[AMFConnection.as:44]
at Main/testConnection()[Main.as:20]
at Main()[Main.as:8]
Where: Main.as:20 = conn.gogogo(...), and AMFConnection.as:44 = _netConnection.connect(url);
It also fails to display the stage, instead showing the loading dots. Now, eventually I'm going to move this application to the same server as the AMFPHP service, but even when I try it there with a relative url, instead of an absolute one, it still breaks down at connect(). I've tried changing the publish settings from local only to network only, to no avail.
Any clues? Know a better way to connect to AMFPHP locally?
Cheers in advance!
JB
P.S. Post updated, see top of page.
first, i prefer to use a php file which contains my sql and params. but hey...
The most obvious reason why you might get this error would be a fault in the url i guess. I believe that the standaard gateway.php is written without a capital G. and does not situate itself in the core folder but in the amfphp folder. but then again I don't know what you have altered.
Your _netConnection must be null, and you call connect() method on null reference, so you finish with NullPointerException. Show us how you initialize _netConnnection :).
Ok, I basically remade the thing, and after a couple of hours, it decided to work. I'm not sure how, but... eh.
Thanks all for your help

Overriding public method in dynamically loaded class with AS3 and getDefinitionByName()

I have two SWFs: main.swf and external.swf. main.swf needs to access some methods in external.swf, so it loads external.swf into itself and uses getDefinitionByName("package.Class") to access the class and one of its methods:
var ExternalClass = getDefinitionByName("package.Class") as Class;
var ClassInstance = new ExternalClass();
var NeededFunction:Function = ClassInstance["NeededFunction"] as Function;
var response:String = NeededFunction(param);
Now, I need to extend the functionality of NeededFunction (which is a public method)... I know it's possible to override public methods, but how would I go about this with a dynamically loaded class?
I was thinking I could do something like this, but it doesn't work:
var ClassInstance["NeededFunction"] = function(param1:uint):String {
var newString = "Your number is: "+param1.toString(); //New functionality
return newString;
}
Another way to deal with this could be to have the classes in a package that's accessible by both SWFs. Just add the classes' root folder to your Actionscript path .
Instead of getting a class by using getDefinitionByName , you simply import it. As for overriding , you can create a Class that overrides one of the classes , or you can create an Interface.
import com.yourlocation.ExternalClass;
var external:ExternalClass = new ExternalClass();
Using FlashDevelop this is pretty simple to fix.
Right click your included swc from the Project list.
Choose options then "include library (complete library)".
..you can now use getDefinitionByName to get a unreferenced class from your swc file.