I use this example:
https://github.com/UdaraAlwis/Xamarin-Playground/tree/master/XFNavBarBackBtnClickOverride.
But FindViewById(Resource.Id.toolbar) return null.
In the new project this example working. On my project not working. What else can I check?
MainAcitvity.cs
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
Xamarin.Essentials.Platform.Init(this, bundle);
Forms.Init(this, bundle);
CrossCurrentActivity.Current.Init(this, bundle);
Rg.Plugins.Popup.Popup.Init(this, bundle);
ToastNotification.Init(this);
Xamarin.FormsMaps.Init(this, bundle);
DependencyService.Register<ToastNotification>();
LoadApplication(new App());
Toolbar toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
}
Toolbar.xml
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
styles.xml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MainTheme" parent="MainTheme.Base">
</style>
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#2196F3</item>
<item name="colorPrimaryDark">#1976D2</item>
<item name="colorAccent">#172239</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:datePickerDialogTheme">#style/AppCompatDialogStyle</item>
<item name="android:textAllCaps">false</item>
</style>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#FF4081</item>
</style>
<color name="ListViewHighlighted">#layout/gradient</color>
</resources>
The following line
Toolbar toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
When you didn't define the toolbar as Android.Support.V7.Widget.Toolbar , it will been init as Android..Widget.Toolbar.So the method FindViewById will never find the toolbar in xml .
Instead it as the following line.
Android.Support.V7.Widget.Toolbar toolbar = this.FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
And you need to set the MainPage as a NavigationPage in app.xaml.cs .
MainPage = new NavigationPage(new xxxPage());
Related
I have an issue with my Xamarin Forms Android app where after idling (a number of hours), when the app resumes there will be a blank screen and then it rapidly flickers black and white for a few seconds and then goes blank and freezes up. I don't think it's getting as far as the PCL, and I get no crash logs for it. This happens on debug and release builds and on a number of real devices, including Android 13.
The only remedy is to close the app and reopen and then it works without an issue.
It may coincide with the device theme changing from light to dark and vice versa and a long idle period. If the device theme is changed on demand and the app closed and reopened, it doesn't suffer from the flicker.
Epilepsy warning
I have a video of it: https://drive.google.com/file/d/1baXvGLYpDoM9DUo5Y9L03HovCNfDOKSV/view?usp=share_link
I am really struggling to find where the offending code is, and I can't debug it because it doesn't happen for hours or days.
As for the app, there are two activities:
Splash activity
[Activity(MainLauncher = true, NoHistory = true)]
public class SplashActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
try
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
}
catch (Exception ex)
{
//Attempted error handling
}
}
protected override void OnStart()
{
try
{
base.OnStart();
StartActivity(new Intent(Application.Context, typeof(MainActivity)).PutExtras(Intent));
}
catch (Exception ex)
{
//Attempted error handling
}
finally
{
Finish();
}
}
public override void OnBackPressed() { }
}
And
Main activity
[Activity(Icon = "#mipmap/ic_launcher", Theme = "#style/MainTheme", MainLauncher = false, LaunchMode = LaunchMode.SingleTask, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize, ResizeableActivity = false, NoHistory = false, Exported = true)]
//auth0 intent filter
public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity, IOnSuccessListener
{
INotificationActionService _notificationActionService;
IDeviceInstallationService _deviceInstallationService;
INotificationActionService NotificationActionService => _notificationActionService ??= ServiceContainer.Resolve<INotificationActionService>();
IDeviceInstallationService DeviceInstallationService => _deviceInstallationService ??= ServiceContainer.Resolve<IDeviceInstallationService>();
protected override void OnCreate(Bundle savedInstanceState)
{
try
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Bootstrap.Begin(() => new DeviceInstallationService());
if (DeviceInstallationService.NotificationsSupported)
{
FirebaseMessaging.Instance.GetToken().AddOnSuccessListener(this, this);
}
Rg.Plugins.Popup.Popup.Init(this);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
CrossCurrentActivity.Current.Init(this, savedInstanceState);
Forms.Init(this, savedInstanceState);
InitFontScale();
CachedImageRenderer.Init(true);
_ = typeof(SvgCachedImage);
UserDialogs.Init(this);
LoadApplication(new App());
ProcessNotificationActions(Intent);
}
catch (Exception ex)
{
//Attempted error handling
}
}
public override void OnBackPressed() => Rg.Plugins.Popup.Popup.SendBackPressed(base.OnBackPressed);
public void OnSuccess(Java.Lang.Object result) => DeviceInstallationService.Token = result.ToString();
private void InitFontScale()
{
var configuration = Resources.Configuration;
configuration.FontScale = Math.Min(1f, configuration.FontScale);
//0.85 small, 1 standard, 1.15 big,1.3 more bigger ,1.45 super big
var metrics = new DisplayMetrics();
#pragma warning disable CS0618 // Type or member is obsolete
WindowManager.DefaultDisplay.GetMetrics(metrics);
#pragma warning restore CS0618 // Type or member is obsolete
metrics.ScaledDensity = configuration.FontScale * metrics.Density;
BaseContext.ApplicationContext.CreateConfigurationContext(configuration);
BaseContext.Resources.DisplayMetrics.SetTo(metrics);
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
protected override void OnResume()
{
try
{
var culture = new CultureInfo("en-GB");
CultureInfo.DefaultThreadCurrentCulture = culture;
Thread.CurrentThread.CurrentCulture = culture;
InitFontScale();
base.OnResume();
}
catch (Exception ex)
{
//Attempted error handling
}
}
protected override void OnNewIntent(Intent intent)
{
try
{
base.OnNewIntent(intent);
Auth0.OidcClient.ActivityMediator.Instance.Send(intent.DataString);
ProcessNotificationActions(intent);
}
catch (Exception ex)
{
//Attempted error handling
}
}
private void ProcessNotificationActions(Intent intent)
{
try
{
if (intent?.HasExtra("action") == true)
{
var bundle = intent.Extras;
var dict = bundle.KeySet().ToDictionary(key => key, key => bundle.Get(key).ToString());
var action = intent.GetStringExtra("action");
if (!string.IsNullOrEmpty(action))
{
NotificationActionService.TriggerAction(action, dict);
}
}
}
catch (Exception ex)
{
//Attempted error handling
}
}
}
And
some styles
values styles.xml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MainTheme" parent="MainTheme.Base">
<item name="colorAccent">#3E94FF</item>
<item name="android:datePickerDialogTheme">#style/CustomDatePickerDialog</item>
</style>
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowIsTranslucent">true</item>
</style>
<style name="CustomDatePickerDialog" parent="ThemeOverlay.AppCompat.Dialog">
<!--header background-->
<item name="colorAccent">#3E94FF</item>
<!--selected day-->
<item name="android:colorControlActivated">#3E94FF</item>
<!--cancel&ok-->
<item name="android:textColor">#000000</item>
</style>
</resources>
values-night styles.xml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MainTheme" parent="MainTheme.Base">
<item name="colorAccent">#3E94FF</item>
<item name="android:datePickerDialogTheme">#style/CustomDatePickerDialog</item>
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowIsTranslucent">true</item>
</style>
<style name="CustomDatePickerDialog" parent="ThemeOverlay.AppCompat.Dialog">
<!--selected day-->
<item name="android:colorControlActivated">#3E94FF</item>
<!--cancel&ok-->
<item name="android:textColor">#ffffff</item>
<!--body background-->
<item name="android:windowBackground">#2F343C</item>
<!--days of the month-->
<item name="android:textColorPrimary">#9BA3B1</item>
<!--days of the week-->
<item name="android:textColorSecondary">#ffffff</item>
</style>
</resources>
The application tag in the manifest has the splash theme as the style
android:theme="#style/SplashTheme"
Any help with pinpointing the cause would be very much appreciated.
Thank you.
I have tried combining it into one activity to see if it was the transition from the splash to the main activity.
I have also changed it to the splash activity explicitly starting the main activity and finishing itself, but it made no difference.
As I thought it may be the main activity not getting closed properly, I have also used a timer to finish the activity after 5 minutes in the background, but it still occurred.
Well to start with Android 12 and above doesn't support a separate SplashScreen Activity, so you would need to get rid of that. See https://developer.android.com/develop/ui/views/launch/splash-screen for the full details.
If you want to see how it should be done in Xamarin.Android take a look at https://github.com/gmck/XamarinBasicSplashScreen. Works from API 21 - 33.
I'm trying to make a mobile application with a screen that looks like this:
I'm making this using Corona, it's written in the Lua language
It's a scrollable list of buttons, I somewhat understand the scroll aspect. What I'm having problems now is making a button that can have more than one line of text and also an image. I've literally been searching for hour but haven't found anything (I'm probably bad at finding things). I think I'd have to create a custom button but I have no idea how to do this. I would appreciate some help with this be it a link or just some lines of text explaining it, thank you so much!
use custom view
custom_button_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/iconImgV"
android:layout_alignParentRight="true"
android:layout_width="100dp"
android:layout_alignParentTop="true"
android:background="#ff0000"
android:layout_height="100dp" />
<TextView
android:id="#+id/titleTv"
android:textSize="18sp"
android:text="Title"
android:layout_toLeftOf="#+id/iconImgV"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/descriptionTv"
android:layout_width="wrap_content"
android:text="description"
android:textSize="14sp"
android:layout_below="#+id/titleTv"
android:layout_toLeftOf="#+id/iconImgV"
android:layout_height="wrap_content" />
</RelativeLayout>
and CustomButtonView.java
public class CustomButtonView extends RelativeLayout {
Context context;
//view
ImageView iconImgV;
TextView titleTv, descriptionTv;
//value
int drawableIcon;
String title,description;
public CustomButtonView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.context = context;
init();
}
public CustomButtonView(Context context) {
super(context);
init();
}
public CustomButtonView(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.customButtonViewAttrs);
drawableIcon = typedArray.getInt(R.styleable.customButtonViewAttrs_drawableIcon,0);
title = typedArray.getString(R.styleable.customButtonViewAttrs_title);
description = typedArray.getString(R.styleable.customButtonViewAttrs_description);
typedArray.recycle();
init();
}
public void init() {
if (isInEditMode())
return;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View myView = inflater.inflate(R.layout.custom_button_view, null);
iconImgV = (ImageView) myView.findViewById(R.id.iconImgV);
titleTv = (TextView) myView.findViewById(R.id.titleTv);
descriptionTv = (TextView) myView.findViewById(R.id.descriptionTv);
titleTv.setText(title);
addView(myView);
}
}
and value/attrs.xml
<declare-styleable name="customButtonViewAttrs">
<attr name="title" format="string" />
<attr name="description" format="string" />
<attr name="drawableIcon" format="integer" />
</declare-styleable>
you can use this way
<com.example.rasoul.testprojectstacj.CustomButtonView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:title = "Car"/>
Found a solution, widget.newTable does this perfectly
I am a beginner of android application. I am using Android Studio to make an application for a shopping cart list. For the start, right now, I am working on the creating two buttons on each screens that called, "edit" and "save." So if I click the edit button, it will go to screen2, and if I click the save, it will go to screen1. However, Whenever I tried to lunch it, it's getting an error like this:
02-14 15:14:57.830 AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.jieun.hw1, PID: 1782
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jieun.hw1/com.example.jieun.hw1.MainActivityOne}: java.lang.NullPointerException
My codes for two screens and the layouts are something like this:
Screen1:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
Button editButton = (Button) findViewById(R.id.e_button);
editButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
//Starting a new Intent
Intent editScreen = new Intent(..MainActivityTwo.class);
startActivity(editScreen);
}
});
}
Screen2:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
Button saveButton = (Button) findViewById(R.id.s_button);
saveButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
//Starting a new Intent
Intent saveScreen;
saveScreen = new Intent(getApplicationContext(), MainActivityOne.class);
startActivity(saveScreen);
}
});
}
Layout1:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivityOne">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edit"
android:id="#+id/e_button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
Layout2:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivityOne">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save"
android:id="#+id/s_button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Have you tried looking through your code for screen 1?
Here:
//Starting a new Intent
Intent editScreen = new Intent(..MainActivityTwo.class);
startActivity(editScreen);
}
There are two periods before MainActivityTwo.class
I am trying to implement a popup in my application but it won't dismiss. The Popup is supposed to open when I click on a Plus button, and this works. However, it is supposed to close when I click on the Cancel button in popup layout but it doesn't. why?
Popup layout (tempo_popup.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1" >
<Button
android:id="#+id/confirmtempo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Confirm" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1" >
<Button
android:id="#+id/canceltempo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Cancel" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Java code:
public class MetronomeActivity extends Activity{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_metronome);
final Button plus = (Button) findViewById(R.id.tempop);
final Button minus = (Button) findViewById(R.id.tempom);
final Button confirm_tempo = (Button) findViewById(R.id.confirmtempo);
plus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View pop = inflater.inflate(R.layout.tempo_popup, null, false);
final PopupWindow pw = new PopupWindow(
inflater.inflate(R.layout.tempo_popup, null, false),
250, 150, true);
// The code below assumes that the root container has an id called 'main'
pw.showAtLocation(plus, Gravity.CENTER, 0, 0);
Button cancel_tempo = (Button) pop.findViewById(R.id.canceltempo);
cancel_tempo.setOnClickListener( new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.i("Begin1", "POPUP CANCEL");
pw.dismiss();
}
});
}
});
}
}
Damn it! Replace single line of code, it will work like charm.
Instead:
PopupWindow popUpWindow = new PopupWindow(inflater.inflate(R.layout.tempo_popup, null, false),250, 150, true);
Use:
View view = inflater.inflate(R.layout.tempo_popup, null, false);
PopupWindow popUpWindow = new PopupWindow(view, 250, 150, true);
Does the Popup cancel log get printed? Otherwise this might help:
Android popup window dismissal
I have embedded Flashpunk game library to my Flex/Air project where some Flex components are rendered on top of the FP. Things show correctly and Flex components respond to mouse input. Flashpunk however doesn't. I embedded it like this:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
resize="windowedapplication1_resizeHandler(event)"
initialize="init();"
applicationComplete="complete();"
showStatusBar="false"
mouseEnabled="false"
xmlns:local="*">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:SpriteVisualElement id="flashpunk" depth="-2" mouseEnabled="true" mouseChildren="true">
</s:SpriteVisualElement>
<mx:MenuBar id="myMenubar" width="832" itemClick="menuHandler(event);" labelField="#label" depth="0">
<fx:XMLList xmlns="">
<item label="File">
<item label="New" id="new" />
<item label="Open" id="open"/>
<item label="Save" id="save"/>
<item label="Save As" id="saveas"/>
<item label="Quit" id="quit"/>
</item>
<item label="Edit">
<item label="Undo" id="undo"/>
<item label="Redo" id="redo"/>
<item label="Preferences" id="preferences"/>
</item>
<item label="Level">
<item label="New Scene" id="newroom"/>
<item label="Properties" id="properties"/>
</item>
<item label="Objects">
<item label="Clickable" id="clickable"/>
<item label="Character" id="character"/>
<item label="Door" id="door"/>
<item label="Treasure" id="treasure"/>
</item>
</fx:XMLList>
</mx:MenuBar>
<fx:Script>
<![CDATA[
import basicui.Global;
import basicui.NewUI;
import flash.display.NativeWindow;
import flash.display.StageScaleMode;
import flash.filesystem.File;
import mx.collections.*;
import mx.controls.Alert;
import mx.core.IUIComponent;
import mx.core.InteractionMode;
import mx.core.mx_internal;
import mx.effects.effectClasses.FadeInstance;
import mx.events.FlexNativeWindowBoundsEvent;
import mx.events.MenuEvent;
import mx.events.ResizeEvent;
import mx.utils.object_proxy;
import net.flashpunk.FP;
import net.flashpunk.Screen;
import org.osmf.elements.F4MElement;
import spark.components.Application;
import spark.components.supportClasses.InteractionState;
public var Maini:Main = new Main;
public static var windowsize:Point = new Point(640, 480);
private var started:Boolean = false;
private function init():void
{
flashpunk.addChild(Maini);
Global.main = this;
}
private function complete():void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
//calculate system chrome
//nativeWindow.width = 640;
//nativeWindow.height = 480;
Global.chromew=nativeWindow.width-nativeWindow.stage.stageWidth;
Global.chromeh=nativeWindow.height-nativeWindow.stage.stageHeight;
Global.uibarh = 50;
//default windowsize
resizewindow(windowsize.x, windowsize.y);
started = true;
}
public function resizewindow(w:int, h:int):void
{
if (w < 640)
w = 640;
if (h < 480)
h = 480;
windowsize.x = w+Global.chromew;
windowsize.y = h+Global.chromeh+Global.uibarh;
nativeWindow.width = w+Global.chromew;
nativeWindow.height = h +Global.chromeh+Global.uibarh;
myMenubar.width = nativeWindow.width;
//resize flashpunk
FP.width = nativeWindow.width;
FP.height = nativeWindow.height;
FP.screen = new net.flashpunk.Screen;
FP.bounds.width = Number(FP.width);
FP.bounds.height = Number(FP.height);
}
private function menuHandler(evt:MenuEvent):void
{
// Don't open the Alert for a menu bar item that
// opens a popup submenu.
if (evt.item.#id == "new")
{
var a:NewUI = new NewUI;
a.begin(this);
addElement(a);
}
if (evt.item.#id == "open")
{
var filter:FileFilter = new FileFilter("Levels", "*.ael");
var file:File = new File;
file.browseForOpen("",[filter]);
file.addEventListener(Event.SELECT, fileselected);
}
if (evt.item.#id == "quit")
{
//close the program
//could ask if there is unsaved data...?
close();
}
/*Alert.show("Label: " + evt.item.#label + "\n" +
"Data: " + evt.item.#data, "Clicked menu item");
*/
}
private function fileselected(event:Event):void
{
//user selected a file:
File(event.currentTarget).addEventListener(Event.COMPLETE, fileloaded)
File(event.currentTarget).load();
}
private function fileloaded(event:Event):void
{
//user selected file is loaded:
Global.levelfile = File(event.currentTarget);
Global.levelXML = XML(File(event.currentTarget).data.toString());
//initialize level project
Global.editor.initlevel();
}
protected function windowedapplication1_resizeHandler(event:ResizeEvent):void
{
// TODO Auto-generated method stub
if (started)
{
windowsize.x = nativeWindow.width;
windowsize.y = nativeWindow.height
myMenubar.width = nativeWindow.width;
}
}
]]>
</fx:Script>
</s:WindowedApplication>
Flashpunk library has its own event listeners for input "Input.as". For some reason they seem to not run. I suppose that the flex components somehow hijacks these listeners or that the SpriteVisualElement doesn't allow or recognize them. How I can enable SpriteVisualElement event listeners? Is there setting I need to set or something? Note that neither mouse or keyboard input doesn't work.
EDIT: Added my main mxml code. Is there way to create a "catch all" listener which would then feed events to the FP's Input class?