Coder Social home page Coder Social logo

fabrice-montfort / fresharp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tuarua/fresharp

0.0 2.0 0.0 1.56 MB

C# wrapper for FlashRuntimeExtensions

License: Apache License 2.0

C# 51.82% C++ 12.08% Batchfile 3.48% ActionScript 9.59% C 1.29% Objective-C 1.00% Pascal 6.28% Inno Setup 14.46%

fresharp's Introduction

FreSharp

paypal

Features

  • Build Adobe Air Native Extensions using C#

Please see the feature rich example in https://github.com/tuarua/FreSharp/tree/master/example

The package is hosted on NuGet at https://www.nuget.org/packages/TuaRua.FreSharp/


How to use

Example - Convert a FREObject into a String, and String into FREObject

try {
   var airString = argv[0].AsString();
   Trace("String passed from AIR:" + airString);
}
catch (Exception e) {
  Console.WriteLine(@"caught in C#: type: {0} message: {1}", e.GetType(), e.Message);
}
const string sharpString = "I am a string from C#";
return sharpString.ToFREObject();

Example - Call a method on an FREObject

var person = argv[0];
var addition = person.Call("add", 100, 33);
Trace("result is: ", addition.AsInt());

Example - Get a property of a FREObject

var oldAge = person.GetProp("age").AsInt();
Trace("result is: ", oldAge);

Example - Convert a FREObject Object into a Dictionary

var dictionary = person.AsDictionary();
var name = dictionary["name"];

Example - Create a new FREObject

var newPerson = new FREObject().Init("com.tuarua.Person");
Trace("We created a new person. type =", newPerson.Type());

Native Stage - Adding native elements over the AIR window
The example includes AIRNativeANE for creating a child Window which can be used to contain WPF controls and graphics. In Windows 8.1+ the Window can be transparent. Buttons and images can be added easily from actionscript.

ANStage.init(stage, new Rectangle(100, 0, 400, 600), true, true);
ANStage.add();

var nativeButton = new ANButton(new TestButton(), new TestButtonHover());
nativeButton.addEventListener(MouseEvent.CLICK, onNativeClick);
var nativeSprite:ANSprite = new ANSprite();
nativeSprite.x = 150;

var nativeImage:ANImage = new ANImage(new TestImage());
ANStage.addChild(nativeSprite);
ANStage.addChild(nativeImage);
ANStage.addChild(nativeButton);

Advanced Example - Extending FreObjectSharp. Creating a C# version of flash.geom.point

using System.Collections;
using System.Windows;
using TuaRua.FreSharp;
using FREObject = System.IntPtr;

namespace FreSharp.Geom {
    public class FrePointSharp : FreObjectSharp {
        public FrePointSharp() { }
        public FrePointSharp(FREObject freObject) {
            RawValue = freObject;
        }
        public FrePointSharp(Point value) {
            uint resultPtr = 0;
            var args = new ArrayList {
                value.X,
                value.Y
            };

            RawValue = FreSharpHelper.Core.getFREObject("flash.geom.Point", FreSharpHelper.ArgsToArgv(args),
                FreSharpHelper.GetArgsC(args), ref resultPtr);
            var status = (FreResultSharp) resultPtr;

            if (status == FreResultSharp.Ok) {
                return;
            }
            FreSharpHelper.ThrowFreException(status, "cannot create point ", RawValue);
        }
        public void CopyFrom(FrePointSharp sourcePoint) {
            uint resultPtr = 0;
            var args = new ArrayList {
                sourcePoint.RawValue,
            };
            FreSharpHelper.Core.callMethod(RawValue, "copyFrom", FreSharpHelper.ArgsToArgv(args),
                FreSharpHelper.GetArgsC(args), ref resultPtr);
            var status = (FreResultSharp) resultPtr;
            if (status == FreResultSharp.Ok) {
                return;
            }
            FreSharpHelper.ThrowFreException(status, "cannot copyFrom ", FREObject.Zero);
        }
        public new Point Value => new Point(
            RawValue.GetProp("x").AsDouble(), 
            RawValue.GetProp("y").AsDouble());
    }
}

Tech

Uses .NET 4.6

Prerequisites

You will need

  • Visual Studio 2017
  • AIR 19+ SDK

Todos

fresharp's People

Contributors

tuarua avatar

Watchers

James Cloos avatar Fabrice Montfort avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.