How to use the trace method in Flambe? - haxe

I am trying to use the trace method to print a string on the screen. I thought that Haxe code should work in Flambe, but apparently it doesn't. I tried to run this code but all I get is a black screen:
package urgame;
class Main {
static public function main():Void {
trace("Hello World");
}
}
I took the code from this haxe guide.
I also tried to use this code but the result is identical (black screen):
package urgame;
import flambe.Entity;
import flambe.System;
import flambe.asset.AssetPack;
import flambe.asset.Manifest;
import flambe.display.FillSprite;
import flambe.display.ImageSprite;
import flambe.display.Sprite;
class Main
{
private static function main ()
{
// Wind up all platform-specific stuff
System.init();
// Load up the compiled pack in the assets directory named "bootstrap"
var manifest = Manifest.fromAssets("bootstrap");
var loader = System.loadAssetPack(manifest);
loader.get(onSuccess);
}
private static function onSuccess (pack :AssetPack)
{
trace('Hello World');
}

If you run the html version the traces should be displayed in the browser console. So do build and run (debug build) and hit F12 in the browser.

Related

nodejs with tap: Class extends value undefined is not a constructor or null

I'm pretty new to node development and have the issue mentioned in the headline. I figured out, that this is probably a circular dependency issue. But I really don't get why.
Maybe you can help?
Here is the first part of my application that works.
I have a simple abstract class like this:
export abstract class AbstractApplication {
abstract beforeStart(): void
abstract afterStart(): void
}
Then I have a second class that extends from that AbstractApplication:
export class App extends AbstractApplication {
//implement the specific methods from AbstractApplication here and do things
async startApp(): void {
//do things here
}
}
Inside this same file, I create an instance of the App class and export it into the module like this:
const app: App = new App()
module.exports = app
Then, inside another file, the server.js, I require this app and start it like this:
const app = require("./src/App")
app.startApp()
And if I run npm run start which calls node server.js everything works and the App runs.
Now I have a seperate file that contains a third class that extends from the App class like this:
export class TestSuite extends App {
async startApp(): Promise<void> {
console.log("READY")
}
}
So as you can see, I take the app class but I override the startApp function.
Inside this same file I do the same thing I did in the App file before:
const testSuite = new TestSuite()
module.exports = testSuite
Then in a last file, I'm doing this:
const testSuite = require("./TestSuite")
testSuite.startApp()
If I now change my npm start to node theOtherFileWithTestSuiteStart.js and run npm run start, everything works also fine.
Now, the last file which contains the testSuite.startApp()should contain test functions that depend on that application, just something simple as
const testSuite = require("./TestSuite")
testSuite.startApp()
test('requests the "/" route', function () {
//test something here
})
And when I run this with tap, then I get the error above: TypeError: Class extends value undefined is not a constructor or null
The interesting thing is: If I extend the TestSuite class from AbstractApplication, I at least get an error that the test is unfinished (which may be okay because of dummy implementation). If I extend it from the App class, this error occures.
Any ideas?

Phaser 3 ScaleManager exception

I am trying to enable fullscreen in my game written in Phaser 3.
I am doing it from Scene class via
this.game.scale.startFullScreen();
but getting error in f12 browser console
Uncaught TypeError: this.game.scale.startFullScreen is not a function
at TitleScene.<anonymous> (TitleScene.js:23)
at InputPlugin.emit (phaser.js:2025)
at InputPlugin.processDownEvents (phaser.js:167273)
...
In docs ScaleManager class has startFullScreen method.
Why console tells me it doesn't?
This is the full code of TitleScene.js:
export class TitleScene extends Phaser.Scene {
constructor ()
{
const config =
{
key: 'TitleScene'
}
super(config);
}
preload ()
{
this.load.image('Title', 'assets/Title.png');
}
create ()
{
this.background = this.add.image(960, 540, 'Title');
this.input.manager.enabled = true;
this.input.once('pointerdown', function () {
this.scene.start('MainScene');
this.game.scale.startFullScreen(); // here is the error
}, this);
}
}
There are two problems prevented me from resolving this problem:
I followed examples from here
https://www.phaser.io/examples/v2
But I am using the third version Phaser. And everyone who uses the same must follow examples from here
https://www.phaser.io/examples/v3
You must pay attention to url while using their site with examples. Both pages are the same from the first look. But urls are different. Also there are warning after each example using the second (old) version of engine.
And finally this function name is not startFullScreen but startFullscreen :)

Parent/Child class hierachy in nodejs

child.js
class Child {
constructor(){
this.helloWorld = "Hello World";
}
run() {
}
}
export default new Child();
parent.js
import child from './child.js';
class Parent {
constructor() {
this.child = child;
}
}
export default new Parent();
index.js
import parent from './parent.js'
console.log(parent.child.helloWorld); <-- does not throws an error, displays "Hello World"
console.log(parent.child.run); <-- throws an error (Cannot read property run from undefined)
console.log(parent.child.run()); <-- throws an error (Cannot read property run from undefined)
If I do console.log(parent.child) in index.js, run does not show up, however the property helloWorld does..
How can I have the functions exposed as well? I was hoping to be able to do this to help keep my code a bit more organized, so was going to separate it out into separate classes to help minimize the amount of code in each file.
To make one thing clear from the start: The error you seem to get has nothing to do with run not appearing in the console.log output.
If your code really throws that error then that means that the value of parent.child is undefined. Hence when you call console.log(parent.child), you should see undefined, not an object. However, I don't see why you'd get that error.
Anyways, run is defined on the prototype of parent.child, not on itself. console.log most likely shows an object's own properties (the console API is not standardized, so results can vary between environments). That's normal.
Simple example to reproduce:
var foo = {
x: 42
};
var bar = Object.create(foo);
bar.y = 21;
console.log(bar, bar.x, bar.y);
// Open the browser console to see output
bar.x is accessible even though console.log doesn't show it (in Chrome at least).
Well I'm not sure if helps you to solve the problem, but whenever I want to add inheritance, I use extends and super here is an example:
Base Class:
class BaseDataModel {
constructor() {
}
getModel() {
return 'model';
}
module.exports.BaseDataModel = BaseDataModel;
Class extending Base Class:
"use strict"
// Imports
const BaseDataModel = require('../baseDataModel').BaseDataModel; // use the proper location
class UserMembershipModel extends BaseDataModel {
constructor() {
super(); // this is optional, I use this to inherit the constructors
}
getChildModel() {
return super.getModel(); // This is how you access the function from your extended class
}
module.exports.UserMembershipModel = UserMembershipModel;
Again, not sure if it solves your problem, since your actually adding a property with a Child class. My example is actually extending (or UserMembershipModel inherits from BaseDataModel).
Hope this helps you a bit.

Using dart2js output with Cloud Code by Parse.com

First, I transpose the javascript example into a dart one.
JS
Parse.Cloud.define('hello', function(request, response) {
response.success('Hello world');
});
DART
import 'dart:js' show allowInterop;
import 'package:js/js.dart' show JS;
#JS('Parse.Cloud.define')
external void define(String name, Function func);
void main() {
define('hello', allowInterop((req, res) {
res.success('Yeah!');
}));
}
Then I compile it using dart2js (with csp or not).
Finally I run parse deploy and I get
ReferenceError: self is not defined
at <error: TypeError: Object #<error> has no method '__lookupGetter__'>
at main.js:2539:9
at init.currentScript (main.js:2519:7)
at main.js:2534:5
at main.js:2542:3
and now, here I am...
How I could get it work on parse.com which is a nodejs env I presume.
self is effectively not defined in the environement provided by parse.com, so I defined self such as var self = this; in the dart2js output.
I get a new error, about success$1 is not defined. Well, that's true, my code is still incomplet...
Dart code should like this:
import 'dart:js' show allowInterop;
import 'package:js/js.dart' show JS, anonymous;
#JS('Parse.Cloud.define')
external void define(String name, Function func);
#JS()
#anonymous
class HttpResponse {
external void success(String msg);
external void error(String msg);
}
void main() {
define('hello', allowInterop((req, HttpResponse res) {
res.success('Yeah!');
}));
}
Now, everything work. I can enjoy my sunday.

Error.getStackTrace() returns a string unparseable in flashdevelop?

Accessing a string created by an Error's getStackTrace function is resulting in very unusual behaviour in the FlashDevelop IDE.
package
{
import flash.display.Sprite;
public class Main extends Sprite
{
public function Main():void
{
print("Start");
var err:Error = new Error();
var stack:String = err.getStackTrace();
print(stack);
// also occurs when this is replaced with stack.length or stack[0]
print("End");
}
private function print(input:*):void
{
trace(input);
trace("---");
}
}
}
When run in flash CS4 that outputs
Start
---
Error
at Main()
---
End
---
But when run in FlashDevelop (replacing trace() with FlashConnect.trace()) it outputs
Start
---
Is that a bug, or is it FlashDevelop handling errors in a different way intentionally?
If it is the latter is there a workaround to access the stacktrace of an error?
I managed to fix this by switching to using a dubugging version of the flash player, i hope this helps anyone else with this problem.
instructions for specifying a debug player
Make sure you are compiling in Debug configuration and you may have to enable (set True) "Verbose Stack Trace" in your Project Properties > Compiler Options

Resources