11-19-2010 02:34 AM
first of all, I'm very new to ActionScript. I just started and I'm now really confuse.
I'm trying to load a new page from another as file when clicked "register", but I just can't get anything to display after clicking
please Help
here's my source code
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.TextEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import qnx.media.QNXStageWebView;
import qnx.ui.buttons.Button;
import qnx.ui.display.Image;
import qnx.ui.text.TextInput;
[SWF(width="1024", height="600", backgroundColor="#cccccc", frameRate="30")]
public class LoginDemo extends Sprite
{
private var webView:QNXStageWebView;
public function LoginDemo()
{
drawLayout();
}
private function drawLayout():void
{
var myFormat:TextFormat = new TextFormat
myFormat.color = 0xAA0000;
myFormat.size = 18;
myFormat.font = "tahoma"
myFormat.align = "left";
var hdFormat:TextFormat = new TextFormat
hdFormat.color = 0xAA0000;
hdFormat.size = 12;
hdFormat.font = "tahoma";
hdFormat.align = "left";
var txtFormat:TextFormat = new TextFormat
txtFormat.color = 0xFFFFFF;
txtFormat.size = 18;
txtFormat.font = "tahoma"
txtFormat.align = "left";
var btnTxtFormat:TextFormat = new TextFormat
btnTxtFormat.color = 0x000000;
btnTxtFormat.size = 16;
btnTxtFormat.font = "tahoma"
btnTxtFormat.align = "center";
var text:TextField = new TextField();
text.text = "x";
text.width = 20;
text.height = 20;
text.x = stage.stageWidth - 50;
text.y = logoImg.height + 10;
text.setTextFormat(myFormat);
var closeButton:Button = new Button();
closeButton.addChild(text);
closeButton.addEventListener(MouseEvent.CLICK, closeWindow);
closeButton.width = 20;
closeButton.height = 20;
closeButton.x = stage.stageWidth - 50;
closeButton.y = logoImg.height + 10;
addChild(closeButton);
var userInput:TextInput = new TextInput();
userInput.width = 200;
userInput.height = 30;
userInput.x = (stage.stageWidth - userInput.width)/2;
userInput.y = (stage.stageHeight - userInput.height)/2;
addChild(userInput);
var passInput:TextInput = new TextInput();
passInput.width = 200;
passInput.height = 30;
passInput.x = (stage.stageWidth - passInput.width)/2;
passInput.y = userInput.y + userInput.height + 5;
addChild(passInput);
var userTxt:TextField = new TextField();
userTxt.text = "Username :";
userTxt.x = userInput.x - userTxt.width - 10;
userTxt.y = userInput.y;
userTxt.width = 120;
userTxt.setTextFormat(txtFormat);
addChild(userTxt);
var passTxt:TextField = new TextField();
passTxt.text = "Password :";
passTxt.x = passInput.x - passTxt.width - 10;
passTxt.y = passInput.y;
passTxt.width = 120;
passTxt.setTextFormat(txtFormat);
addChild(passTxt);
var loginTxt:TextField = new TextField();
loginTxt.text = "login";
loginTxt.width = 95;
loginTxt.height = 30;
loginTxt.setTextFormat(btnTxtFormat);
var loginBtn:Button = new Button();
loginBtn.x = (stage.stageWidth - passInput.width)/2;
loginBtn.y = passInput.y + passInput.height + 20;
loginBtn.width = 95;
loginBtn.height = 30;
loginBtn.addChild(loginTxt);
addChild(loginBtn);
var clrTxt:TextField = new TextField();
clrTxt.text = "cancel";
clrTxt.width = 95;
clrTxt.height = 30;
clrTxt.setTextFormat(btnTxtFormat);
var clrBtn:Button = new Button();
clrBtn.x = ((stage.stageWidth - passInput.width)/2) + loginBtn.width + 10;
clrBtn.y = passInput.y + passInput.height + 20;
clrBtn.width = 95;
clrBtn.height = 30;
clrBtn.addChild(clrTxt);
//clrBtn.addEventListener(MouseEvent.CLICK, registerEvt);
addChild(clrBtn);
var plsLoginTxt:TextField = new TextField();
plsLoginTxt.text = "Please Login !";
plsLoginTxt.x = (stage.stageWidth/2) - userInput.width + 20;
plsLoginTxt.y = userInput.y - 40;
plsLoginTxt.width = 150;
plsLoginTxt.setTextFormat(hdFormat);
addChild(plsLoginTxt);
var askTxt:TextField = new TextField();
askTxt.text = "Do not have an account ?";
askTxt.setTextFormat(hdFormat);
askTxt.y = loginBtn.y + loginBtn.height;
askTxt.x = (stage.stageWidth - passInput.width)/2;
askTxt.width = 150;
addChild(askTxt);
var regisTxt:TextField = new TextField();
regisTxt.text = "Register.";
regisTxt.setTextFormat(hdFormat);
regisTxt.y = loginBtn.y + loginBtn.height;
regisTxt.x = (stage.stageWidth - passInput.width)/2 + askTxt.width;
regisTxt.addEventListener(MouseEvent.CLICK, regisEvt);
addChild(regisTxt);
}
public function regisEvt(event:MouseEvent):void
{
clearWindow();
var yok:Register = new Register();
}
private function clearWindow():void
{
while(numChildren > 0)
{
removeChildAt(0);
}
if(webView != null)
{
webView.dispose();
}
}
private function closeWindow(event:MouseEvent):void
{
stage.nativeWindow.close();
}
}
}and here is another file i tried to load.
package
{
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.TextEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import qnx.media.QNXStageWebView;
import qnx.ui.buttons.Button;
import qnx.ui.display.Image;
import qnx.ui.text.TextInput;
[SWF(width="1024", height="600", backgroundColor="#cccccc", frameRate="30")]
public class Register extends Sprite
{
public var webView:QNXStageWebView;
public function Register():void
{
var mySprite:Sprite = new Sprite();
var myDisplayObject:DisplayObject = mySprite;
addChild(mySprite);
var txtFormat:TextFormat = new TextFormat();
txtFormat.color = 0xFFFFFF;
txtFormat.size = 18;
txtFormat.font = "tahoma"
txtFormat.align = "left";
var okBtn:Button = new Button();
okBtn.y = 200;
okBtn.x = 350;
okBtn.width = 150;
okBtn.height = 30;
addChild(okBtn);
var regisTxt:TextField = new TextField();
regisTxt.text = "Registration :";
regisTxt.width = 120;
regisTxt.height = 30;
regisTxt.x = 250;
regisTxt.y = logoImg.height + 25;
regisTxt.setTextFormat(txtFormat);
addChild(regisTxt);
var idTxt:TextField = new TextField();
idTxt.text = "Username :";
idTxt.width = 120;
idTxt.height = 30;
idTxt.x = 350;
idTxt.y = regisTxt.y + regisTxt.height + 25;
idTxt.setTextFormat(txtFormat);
mySprite.addChild(idTxt);
var text:TextField = new TextField();
text.text = "x";
text.width = 20;
text.height = 20;
text.x = 974;
text.y = logoImg.height + 10;
text.setTextFormat(txtFormat);
var closeButton:Button = new Button();
closeButton.addChild(text);
closeButton.addEventListener(MouseEvent.CLICK, closeWindow);
closeButton.width = 20;
closeButton.height = 20;
closeButton.x = 974;
closeButton.y = logoImg.height + 10;
addChild(closeButton);
}
private function closeWindow(event:MouseEvent):void
{
stage.nativeWindow.close();
}
}
}thank u
Solved! Go to Solution.
11-19-2010 02:46 AM
This lines:
var mySprite:Sprite = new Sprite();
var myDisplayObject:DisplayObject = mySprite;
addChild(mySprite);
Shouldn't be (guessing here):
var mySprite:LoginDemo = new LoginDemo();
addChild(mySprite);
The only line where one file is using others is:
var yok:Register = new Register();
and nothing more is done with this object, if your intention was to show it, you should add it to stage. You should not add SWF adnotation to every sprite in your application, only to this one which is main application file.
11-19-2010 05:42 AM
Hi, gluth!
thx q for answering
and nothing more is done with this object, if your intention was to show it, you should add it to stage. You should not add SWF adnotation to every sprite in your application, only to this one which is main application file.
this mean that I should have my user interface in main class only, am I right ? or no ? ![]()
thx again !
11-19-2010 05:48 AM
No, not only in main class, you may split them into Sprites by logic construction of your program, by example in above code part you have to logical constructions - login box (have you heard about LoginDialog from SDK?), and other window plus main class. (I'm using QNX Containers, but they are hard to understand). In reaction to events (clicks on buttons, list selections) I'm adding and removing childs from containers (addChild, removeChild) this makes them visible or not. It is somehow similar to screens stack in BB, but here each controll may be in stack, and you may group controlls using Sprites or Containers.
With that approach you will have all GUI and logic corelated with some GUI entity in one place, and it will be easier to manage them, than removing large pile of fields only to put them back few clicks later.
11-23-2010 03:38 AM
I finally got it now. thx a lot.
the thing is at first i add my everything to stage not sprite... Y _ Y
thx q i understand what a sprite and stage is now..
11-24-2010 12:32 AM
"'I'm using QNX Containers, but they are hard to understand"
Out of curiosity, why do you think the QNX containers are hard to understand? I certainly wish there were more containers (like Accordion, and others in the MX world), but that's a different story.
11-24-2010 04:04 AM
Who do I have to kill to have accordion container - header list is not as nice as it could be? When all examples are pixel based with Fields lay out on sprites, you have to learn to use containers on your own. I miss one object which could specify whole style of container (size, direction, position etc.) - just like there is TextFormat for TextFields.
I wish I could know what for is init() function in containers (it is not documented in Tablet SDK) and I'm not sure is it usefull or not, when it is called and by which constructor. I found container very usefull and I'm using them in my applications, they are fast and rather clean to use.
Question: in my application, when I'm calling layout() function after container content change system is ignoring items (or containers) pinned to left or righ side of container. I'm not sure If I'm using them in correct way, but maybe you have meet this kind of behavior in your app.
11-24-2010 08:15 AM
Maybe someone who is versed with Containers could post a tutorial on how they work. That might go along way for this community.
It would be greate if the tutorial covered:
Just adding 2 buttons would be a great helps since documentation is still trying to catch up. I'm surprised someone who likes to blog has not setup one for the PB yet.
I have not played a lot with containers, because I found it slightly confusing the number of steps needed to just get it setup. In the MX world, all you would have to do for a horizontal container is:
var hbox : HBox = new HBox();
hbox.percentWidth = 100;
hbox.addChild( new Button() );
this.addChild( hbox );
In QNX Container? That kind of tutorial. Even is someone wants to extend container to a HBox and VBox and post that, that would be helpful.
11-24-2010 08:22 AM
I'm creating draft community article about containers (I like them very much, they are fun). I will improve it with your questions and try to post it to knowledge base in week (I'll try - lot's of work, lot's of fun). I have wrote small tutorial for TextInput field some time ago, and it's still awaits for publication (it's in drafts for publication, not sure If I have requested publication for it in correct way).
Does anybody else have some questions or howto requests for containers? I'll try to cover them (in reasonable way).
11-29-2010 04:06 AM
I found this really HELPFUL library about the container
http://help.adobe.com/en_US/FlashPlatform/referenc
Please Check it out !!
I wish this would help you like it do to me.. ![]()