Change project from MXML to AS error
I am trying to change a Flex mobile application using MXML to describe views, to one which uses AS3 to create the views. I changed:
BEFORE: Assessments.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:MobileApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" firstView="view.LoginView">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</s:MobileApplication>`
AFTER: Assessments.as
package {
import spark.components.MobileApplication;
import view.LoginView;
[SWF(height="600", width="1024", frameRate="30", backgroundColor="#FFFFFF")]
public class Assessments extends MobileApplication{
public function Assessments(){
super();
super.firstView = view.LoginView;
}
}
}
However, now I am getting the error:
TypeError: Error #1007: Instantiation attempted on a non-constructor.
at mx.preloaders::Preloader/initialize()[E:\dev\hero_private_beta\frameworks\projects\framework\src\mx\preloaders\Preloader.as:258]
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::initialize()[E:\dev\hero_private_beta\frameworks\projects\framework\src\mx\managers\SystemManager.as:1977]
at mx.managers::SystemManager/initHandler()[E:\dev\hero_private_beta\frameworks\projects\framework\src\mx\managers\SystemManager.as:2479]
I believe it may be something to do with the Namespaces not being set in the .as version? Any ideas?
UPDATE
package view
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import net.airpoint.northgate.ui.components.AirpointNumericTextField;
import qnx.events.QNXApplicationEvent;
import qnx.system.QNXApplication;
import spark.components.Button;
import spark.components.Form;
import spark.components.FormHeading;
import spark.components.FormItem;
import spark.components.Label;
import spark.components.TextInput;
import spark.components.View;
public class LoginView extends View
{
private var form:Form;
private var usernameLabel:Label;
private var usernameField:AirpointNumericTextField;
private var passwordLabel:Label;
private var passwordField:TextInput;
private var submit:Button;
// public var menu:AirpointAppMenu;
public function LoginView()
{
// menu = new AirpointAppMenu();
// QNXApplication.qnxApplication.addEventListener(QNXApplicationEvent.SWIPE_DOWN, showAppMenu);
initializeUI();
}
public function showAppMenu(event:QNXApplicationEvent):void{
// menu.show();
}
public function initializeUI():void{
form = new Form();
this.submit = new Button();
this.submit.label = "Login...";
form.defaultButton = this.submit;
// Heading
var fh:FormHeading = new FormHeading();
fh.label = "Login";
form.addElement(fh);
// Username
this.usernameField = new AirpointNumericTextField();
var f1:FormItem = new FormItem();
f1.label = "Username";
f1.addElement(this.usernameField);
// Password
this.passwordField = new TextInput();
this.passwordField.displayAsPassword =true;
var f2:FormItem = new FormItem();
f2.label = "Password";
f2.addElement(this.passwordField);
form.addElement(f1);
form.addElement(f2);
form.addElement(this.submit);
this.addElement(form);
}
}
}
Update 3 AssessmentsApp.as
package {
import mx.events.FlexEvent;
import mx.styles.CSSStyleDeclaration;
import spark.components.Group;
import spark.components.MobileApplication;
import views.AssessmentsAppHome;
[SWF(height="600", width="1024", frameRate="30", backgroundColor="#000")]
public class AssessmentsApp extends MobileApplication{
public function AssessmentsApp(){
super();
this.a开发者_JAVA技巧ddEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete);
}
private function onAppComplete(e:FlexEvent):void
{
this.removeEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete);
firstView = views.AssessmentsAppHome;
}
}
}
AssessmentsAppHome.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="Home">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:VGroup>
<s:TextInput text="awdwdawd"/>
</s:VGroup>
</s:View>
Error
Preloader.as (Fails on displayClass = new... )
// Create a new instance of the display class and attach it to the stage
if (showDisplay)
{
displayClass = new displayClassName();
// Listen for when the displayClass no longer needs to be on the stage
displayClass.addEventListener(Event.COMPLETE, displayClassCompleteHandler);
You should extend Sprite
(not MobileApplication
). See the following link.
Try this instead:
package {
import spark.components.MobileApplication;
import view.LoginView;
[SWF(height="600", width="1024", frameRate="30", backgroundColor="#FFFFFF")]
public class Assessments extends MobileApplication{
public function Assessments(){
super();
this.addEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete);
}
private function onAppComplete(e:FlexEvent):void
{
this.removeEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete);
firstView = LoginView;
}
}
It could be that your ViewNavigator isn't instantiated yet when trying to access it in the constructor.
精彩评论