Flash Builder 4.5 :: Preloader :: How to access the preloader object from Application - flash-builder

Working with Flash Builder 4.5 I have implemented a custom preloader by extending SparkDownloadProgressBar. Now I want the preloader to stay on the screen until my Application has loaded in external data. Once the Application external data has loaded, I want to have the preloader dispatch the Event.COMPLETE event.
The intent is to have a 3 phase preloader.
1st load the RSLs,
2nd the SWF,
3rd application will load the data.
I've overridden the initCompleteHandler function so it does not fire the Event.COMPLETE event once the swf is loaded. I have a public function in the preloader called removePreloader which fires the Event.COMPLETE event.
There is a property in the Application named preloader but it's null.
How can my application call the preloader?
Thanks,
Gary

I'm not sure if this is the most elegant AS3 solution but it is working. If you have a better method, please post.
In the application mxml, I added the following variable:
public var preloaderFinalFireFunction:Function;
In the preloader (which extends SparkDownloadProgressBar) I override the initCompleteHandler to assign a function that's inside the preloader to the application. When i'm ready for the preloader to be removed, the application calls preloaderFinalFireFunction();
override protected function initCompleteHandler(event:Event):void{
var app:MyApplication = MyApplication(FlexGlobals.topLevelApplication);
app.preloaderFinalFireFunction = removePreloader;
}
protected function removePreloader():void{
var app:MyApplication = MyApplication(FlexGlobals.topLevelApplication);
app.preloaderFinalFireFunction = null;
dispatchEvent(new Event(Event.COMPLETE));
}

Related

JavaFX 8: How to automatically input a file on start-up?

I’m using JavaFX 8 and JDK 1.8.0_77 in IntelliJ with SceneBuilder. I created a basic pixel editor app. I have two windows(stages). One is a 32x128 matrix of Circle Objects placed in a Grid Pane and the other is a Message Center in Main.
You can see the Message Center window at: https://virtualartsite.wordpress.com/message-center/
I want to save messages using the Message Center app and scroll them on an RGB LED matrix that’s also 32x128. I save the messages in ArrayList<> of Message Objects and I write the ArrayList’s Message’s to a serialized file. I write the file calling writeObjArrayList () and input the file calling readObjArrayList().
I am able to write and read the file successfully and .add all the Message objects to the ArrayList on start-up so the user can edit or delete any message from the viewMessages ComboBox. BUT so far, I can only do so if I use a button event to call readObjArrayList(). This is the problem.
I want to read the file “behind the scenes”, when the app starts. I want to automatically read the file when the program starts up; the user shouldn’t have to click on a button.
My best idea was to use the following code which compiles but doesn’t appear to execute any code:
public void windowEvents(WindowEvent event){
if(event.getSource() == viewMessages) readObjArrayList();
}
I thought a WindowEvent would be fired with windowEvents=#OnShow for the ComboBox, viewMessages(FX:ID).
Please advise.
Thanks for your help.
According to the javadoc, the WindowEvent is related to Window showing/hiding actions. As Node classes aren't Windows, installing a WindowEvent handler on it won't have any effect.
Since you are using SceneBuilder, I assume that you must have an FXML file that has a fx:controller class defined. In any controller class, you can add a non-arg initialize() method which will be called right after the FXML file has been processed.
public class YourController {
#FXML
ComboBox viewMessages;
public void initialize() {
readObjArrayList();
}
private void readObjArrayList() {
...
}
}

MvvmCross and back button in Windows Phone app

I'm building a Windows Phone app (8.1 using WinRT) using MvvmCross. To navigate to a new view I using ShowViewModel(). But when I hit the back button on the phone the app is closing instead of navigating back to the first view. How can I do it I want to return to the first view when I hitting the back button?
I solved it to use a interface in my viewmodel with a backbutton event, then I wrote a client speific implementation of it. In the viewmodel I handle the event and called the close method in the my base class MvxViewModel. Read more about my solution on my blog, http://danielhindrikes.se/windows-phone/handle-windows-phone-back-button-pressed-when-using-mvvm/
Here's a simpler solution. Create a base type for all your WP pages that derives from MvxWindowsPage. Then, handle the back key there and route the proper information to your VM:
public abstract class MyBaseView : MvxWindowsPage {
public MyBaseView() {
this.InitializeComponent();
HardwareButtons.BackPressed += HardwareButtons_BackPressed;
}
void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e) {
if (Frame.CanGoBack) {
var vm = ViewModel as MyBaseViewModel;
if (vm != null) {
e.Handled = true;
vm.GoBackCommand.Execute(null);
}
}
}
}
Now, you also have to make sure that you have a base viewmodel which derives from MvxViewModel and from which you derive all your VMs. That base VM should have a GoBackCommand observable property, and executing that command should do a simple Close(this).
To see what's going on under the hood, see this related question: Windows Phone 8.1 Universal App terminates on navigating back from second page?
EDIT
Fixed declaration.

Wix Burn Process not closed

Hello I have custom bootstrapper application. All work fine, but when work is done and i close app process continuing to hang. I've noticed that when i tryed to recompile installer. I have code like this:
protected override void Run()
{
//MessageBox.Show("Run");
// set the global message dispatcher
Dispatcher = Dispatcher.CurrentDispatcher;
// Create the model, view model and the view of the main window.
// The view model handles the enitre ui.
Model model = new Model(this);
MainWindowViewModel viewModel = new MainWindowViewModel(model);
MainWindow mainWindow = new MainWindow(viewModel);
Engine.Detect();
// Create a Window to show UI.
Engine.Log(Microsoft.Tools.WindowsInstallerXml.Bootstrapper.LogLevel.Verbose, "Creating UI");
Engine.CloseSplashScreen();
mainWindow.Show();
// run the threading dispatcher
Dispatcher.Run();
// Finalize the installation (with the finalResult) and quit the process.
Engine.Quit(model.FinalResult);
}
I've debugged it and certainly it calls the function Engine.Quit(0) every time. Sometimes it work fine but sometimes the process dosen't stop. There is no "Shutting down, exit code: " line in log. And i don't know why. Does anybody have an idea what i do wrong
I've noticed that it happens only when i modify two or more packages.

Metro c++ async programming and UI updating. My technique?

The problem: I'm crashing when I want to render my incoming data which was retrieved asynchronously.
The app starts and displays some dialog boxes using XAML. Once the user fills in their data and clicks the login button, the XAML class has in instance of a worker class that does the HTTP stuff for me (asynchronously using IXMLHTTPRequest2). When the app has successfully logged in to the web server, my .then() block fires and I make a callback to my main xaml class to do some rendering of the assets.
I am always getting crashes in the delegate though (the main XAML class), which leads me to believe that I cannot use this approach (pure virtual class and callbacks) to update my UI. I think I am inadvertently trying to do something illegal from an incorrect thread which is a byproduct of the async calls.
Is there a better or different way that I should be notifying the main XAML class that it is time for it to update it's UI? I am coming from an iOS world where I could use NotificationCenter.
Now, I saw that Microsoft has it's own Delegate type of thing here: http://msdn.microsoft.com/en-us/library/windows/apps/hh755798.aspx
Do you think that if I used this approach instead of my own callbacks that it would no longer crash?
Let me know if you need more clarification or what not.
Here is the jist of the code:
public interface class ISmileServiceEvents
{
public: // required methods
virtual void UpdateUI(bool isValid) abstract;
};
// In main XAML.cpp which inherits from an ISmileServiceEvents
void buttonClick(...){
_myUser->LoginAndGetAssets(txtEmail->Text, txtPass->Password);
}
void UpdateUI(String^ data) // implements ISmileServiceEvents
{
// This is where I would render my assets if I could.
// Cannot legally do much here. Always crashes.
// Follow the rest of the code to get here.
}
// In MyUser.cpp
void LoginAndGetAssets(String^ email, String^ password){
Uri^ uri = ref new URI(MY_SERVER + "login.json");
String^ inJSON = "some json input data here"; // serialized email and password with other data
// make the HTTP request to login, then notify XAML that it has data to render.
_myService->HTTPPostAsync(uri, json).then([](String^ outputJson){
String^ assets = MyParser::Parse(outputJSON);
// The Login has returned and we have our json output data
if(_delegate)
{
_delegate->UpdateUI(assets);
}
});
}
// In MyService.cpp
task<String^> MyService::HTTPPostAsync(Uri^ uri, String^ json)
{
return _httpRequest.PostAsync(uri,
json->Data(),
_cancellationTokenSource.get_token()).then([this](task<std::wstring> response)
{
try
{
if(_httpRequest.GetStatusCode() != 200) SM_LOG_WARNING("Status code=", _httpRequest.GetStatusCode());
String^ j = ref new String(response.get().c_str());
return j;
}
catch (Exception^ ex) .......;
return ref new String(L"");
}, task_continuation_context::use_current());
}
Edit: BTW, the error I get when I go to update the UI is:
"An invalid parameter was passed to a function that considers invalid parameters fatal."
In this case I am just trying to execute in my callback is
txtBox->Text = data;
It appears you are updating the UI thread from the wrong context. You can use task_continuation_context::use_arbitrary() to allow you to update the UI. See the "Controlling the Execution Thread" example in this document (the discussion of marshaling is at the bottom).
So, it turns out that when you have a continuation, if you don't specify a context after the lambda function, that it defaults to use_arbitrary(). This is in contradiction to what I learned in an MS video.
However by adding use_currrent() to all of the .then blocks that have anything to do with the GUI, my error goes away and everything is able to render properly.
My GUI calls a service which generates some tasks and then calls to an HTTP class that does asynchronous stuff too. Way back in the HTTP classes I use use_arbitrary() so that it can run on secondary threads. This works fine. Just be sure to use use_current() on anything that has to do with the GUI.
Now that you have my answer, if you look at the original code you will see that it already contains use_current(). This is true, but I left out a wrapping function for simplicity of the example. That is where I needed to add use_current().

Simple example of DispatcherHelper

I'm trying to figure out how can I use DispatcherHelperftom MVVM light toolkit in SL, but I can't find any example.
From home page of this framework I know that
DispatcherHelper class, a lightweight class helping you to create
multithreaded applications.
But I don't know how to use it.
How and for what I can use it?
You only need the DispatcherHelper when yo want to make changes to components on your UI thread, from code that runs on a different thread. E.g. in an Silverlight application you call a web service to retrieve some data asynchroneously, and now want to inform the Ui that the data is present via a OnNotifyPropertyChanged event.
First you have to initialize the DispatcherHelper. In Silverlight you do this in Application_Startup:
//initialize Dispatch helper
private void Application_Startup( object sender, StartupEventArgs e) {
RootVisual = new MainPage();
DispatcherHelper.Initialize();
}
In WPF the initialization is done in the static constructor of you App class:
static App() {
DispatcherHelper.Initialize();
}
Then in your event, handling the completion of your asnc call, use the following code to call RaisePropertyChanged on the UI thread:
DispatcherHelper.CheckBeginInvokeOnUI(
() => RaisePropertyChanged(PowerStatePropertyName)
);
DispatcherHelper.BeginInvokeOnUl expects an Action so you can use any code in here just use
DispatcherHelper.CheckBeginInvokeOnUI(
() => { /* complex code goes in here */ }
);
to do more complex tasks.