-
Help with a *simple* input box using AS3
Could anyone kindly provide a small bit of code that shows how - using AS3 and the Flex 2.0 compiler / SDK (not Flash CS3) - I can have a single input box control, and thus be able to create a login further down the line?
I don't use .MXML files as they don't seem to fit into the same model as using .AS files alone, although that's not to say if there isn't a very valid reason to use them I won't. But using .AS alone would be absolutely superb - thanks to anyone who can help!
-
Senior Member
There is no little bit of code, but to have a reference thread for the future here is what you need to do. First you create a singleton, which you call from Flex.
Flex code:
PHP Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="Root.Run(this)">
</mx:Application>
Singleton:
PHP Code:
package
{
import flash.display.Sprite;
public class Root extends Sprite
{
public static var instance:Root;
public static var myRoot:Object;
public static function Run (_root:Object):void
{
myRoot=_root;
instance=new Root ;
}
public function Root ()
{
myRoot.frameRate=31;
myRoot.width=550;
myRoot.height=400;
buildStage ();
}
private function buildStage ():void
{
var a:Main=new Main ;
}
}
}
Main Class:
PHP Code:
package
{
import flash.display.Sprite;
import mx.controls.TextInput;
import flash.events.Event;
import flash.display.Stage;
//
public class Main extends Sprite
{
private static var myRoot:Object;
//
public function Main ()
{
myRoot=Root.myRoot;
myRoot.addEventListener (Event.ADDED,onAdded);
}
private function onAdded (event:Event):void
{
if (event.target.stage != null)
{
event.target.removeEventListener (Event.ADDED,onAdded);
var c:TextInput=new TextInput ;
event.target.addChild (c);
}
}
}
}
- The right of the People to create Flash movies shall not be infringed. -
-
Cancerinform - I appreciate your help, very much so, and will keep that to hand for future reference for sure...
Though, I've just figured out a different way - which I think means you were answering more of a generic way to access .MXML components (and thus the MX.* framework? Not entirely sure) rather than just provide an input box, which is just
var box:TextField = new TextField();
box.type = "input";
Seems to work easy! I couldn't find this for the life of me!
Thanks again!
-
Senior Member
By this way you avoid mxml completely and can focus on AS3. What I have calling is a TextInput component, since components is what Flex 2 is all about and those you can only call the way I described, since the stage has to be not null.
- The right of the People to create Flash movies shall not be infringed. -
-
Basic Login System?
Hey, could you give me a basic code to make a login system. Im making a game so i realy need to know it.
I would be greatful
Oh and by any chance do you know how to move people by clicking where you want them to go?
Please dudes IM BEGGING YOU!
-
Basic code to make a login is just two text boxes, both with .type="input" set. One .displayaspassword = true; as well, to make it mask password.
Then you need to have a back-end system in place to validate the login. This can be PHP/ASP, a socket server like Electrotank, or a custom-written socket server - which one are you using?
-
Hehe, emm
I dont know servers and all that stuff, think you can help me?
-
I know game making and all, im just not good at login systems?
-
Login systems are relatively simple - you just send a username and password down the line to a server and get a response. Adding security is important - a simple method of MD5-hashing (Or Sha-1, or your Hash-of-choice) is very effective and very simple to implement. More complicated forms of security involve encryption - which is a different story entirely, as you need to exchange secure keys between client and server. For everything but highly-sensitive applications, an MD5 hash will suffice.
To further that security, make sure that you don't *just* send an MD5 hash of the password, but that you send a 'salt' from the server to the client, add that salt to the password and *then* send the hash down the line. This way, providing that salt only ever gets used once, nobody will be able to spoof a new login connection by simply repeating the MD5 hash they 'sniffed' off the line - which is very easy to do.
If you don't know servers then you'll need to learn a fair bit. There are existing servers (eg, Electrotank) that'll take the real work away from you, but knowing exactly what you're dealing with is extremely important. If you don't you'll run into problems for sure. Making the login system is pretty simple once you've got client->server communication sorted.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|