Posts Under actionscript Category
Super Easy Email Validation AS2
I needed a quick and easy way to check for the basics of an email address. Does it contain “@” and “.” symbols. This is by no meals a foolproof method, so don’t use it for anything big, but if you want to just do a quick test then here you go: var email:String = "name@server.com"; if (email.indexOf("@")!=-1 && email.indexOf(".")!=-1) trace("false"); else trace ("true");
1180 Call to a possibly undefined method navigateToURL
1180 Call to a possibly undefined method navigateToURL If you get the above error when trying to run your flash actionscript 3 file, you are obviously trying to use the navigateToURL() function but have not imported the flash.net library code. The following code before everything will correct the problem. import flash.net.*; ..or a more of a direct unbloated method is as follows: import flash.net.navigateToURL;
How to use a Timer in Actionscript 3
It is really easy to create a Timer in Actionscript 3. Instantiate the Timer Class and pass a time in millions of 1000 to it to work in seconds. var myTimer:Timer = new Timer(1000); Setup an event listener to call a function. myTimer.addEventListener("timer", myTimerEventHandler); Start the Timer. myTimer.start(); Start the Timer. function myTimerEventHandler(event:TimerEvent):void { trace(myTimer.currentCount+" seconds have passed."); } So altogether we have this. var myTimer:Timer…
Actionscript 2 & PHP Data Transfer
In the below example we will use Actionscript 2 to call a remote PHP file that will return data to it. It is a simple way of transferring data between the server and client. Actionscript 2 Code: callRemoteFile = function(ourVariable:String) { var result_lv:LoadVars = new LoadVars(); result_lv.onLoad = function(success:Boolean) { if (success) { …
Actionscript2: Split string by line length with & without word-wrap
Split string into sentences by max line length. This uses a character array but doesn’t use word-wrapping. var personalMessage:String = "You got this far so we reckon that you could be curious enough to learn a little more, we’ll contact you shortly to answer any questions you may have."; _root.myArray = new Array(); _root.myArray = personalMessage.split(""); _root.mySentences = new Array(); var currentCharCount:Number = 0; var currentCharItem:Number = 0; var currentCharString:String…
Set line leading / line spacing in flash actionscript 2
This is how to add text leading using Actionscript 2 for Flash. var txtFormat:TextFormat = new TextFormat(); txtFormat.leading = 5; // change this to whatever you need it to be ttt.setTextFormat(txtFormat); ttt2.setTextFormat(txtFormat);</span> There is also a GUI way of doing this: Select your textfield and and under the paragraph section, set the top/right hand icon (Line Spacing) to whatever you like.
Error 1046: Type was not found or was not a compile-time constant: Event.
Error 1046: Type was not found or was not a compile-time constant: Event. You need to import the Event class! import flash.events.Event
Add a date to a date in Actionscript 2
I needed to work out a date range according to the date 3weeks away from the current date. After a bit of thinking, I found that it’s actually quite easy to achieve. var theDate:Date = new Date(); dateDay = theDate.getDate(); dateMonth = theDate.getMonth(); dateYear = theDate.getFullYear(); var theDate2:Date = new Date(dateYear,dateMonth,dateDay); theDate2.setDate(theDate2.getDate() + 21); dateDay2 = theDate2.getDate(); dateMonth2 = theDate2.getMonth(); dateYear2 = theDate2.getFullYear();</span> The above code gets the current date…
Add a month to selectable date range – Date Chooser – Actionscript 2
I have been working on a project where I need to select a date range starting today and ending a month from now, so the user cannot select anything in the past or over a month from now. This is how I did it: There is an instance of DateChooser on the stage with Instance Name “calDate”. var todayDate:Date = new Date(); dateBeginDay = todayDate.getDate(); dateBeginMonth = todayDate.getMonth(); dateBeginYear =…
hitTest and Actionscript2
if (mc.hitTest(_root._xmouse, _root._ymouse, true))) { trace("hitTest Run"); }
Limited numeric input in flash actionscript 2 textfield
If you want to only show numeric characters in a textfield in flash actionscript you can use the following code: myTextField.restrict = "0-9";
Enable / Disable Cursor Hand in Actioncsript 2
If you have a movieclip that by default has the hand cursor showing on RollOver and you don’t really want this, you can disable it by doing the following: myMC.onRollOver = function() { this.useHandCursor=false; } So the main code here is: this.useHandCursor=false; False disables it and true shows it.