Results 61 to 75 of 129
Thread: Useful Code Snippets
-
September 6th, 2007, 02:22 PM #61
@wesball
you would have to use a fadeIn function that i have not posted yet, if you get creative with the fade function, you can convert it into a working fadeIn function
-
September 6th, 2007, 02:59 PM #622Registered User
postsHEllo ALL, I am new to forum but have used for almost 7 months.
I have an issue I think may be easy for some but for me it has given a bit of a head ache.
I would like too: have a user select multiple radio buttons and depending on what they select have them gotoAndStop at a certain frame.
I used a case switch to do this which works, but I am not able allow the user to select more or less than a given number
CODE:
var arr:Array = [];
////////////radiobuttons///////////////////
var rbL:Object = {};
rbL.click = function(obj:Object){
var sel = obj.target;
var dat = sel.data;
trace(sel+" - data - "+dat);
arr.push(dat);
};
for(var n:Number=1; n!=6; n++){
var init:Object = {_x:50, _y:n*40+280, label:n, data:n, groupName:"rb"+n};
var ref:MovieClip = this.attachMovie("RadioButton", "RB_"+n, n+1000, init);
ref.addEventListener("click", rbL);
}
////////////submit button///////////////////
this.attachMovie("Button","btnSubmit",2000,{_x:75, _y:675, label:"Design Studio"});
var Submit:Object = {};
Submit.click = function(){
var str:String = "";
for(var m:Number=0; m!=5; m++){ // take first 3 entries only
str += arr[m];
}
switch(str){
case "12345":
_root.gotoAndStop("vocal1");
break;
case "23451" :
_root.gotoAndStop("vocal2");
break;
case "231" :
_root.gotoAndPlay("studio1");
break;
case "213" :
_root.gotoAndPlay("studio1");
break;
case "312" :
_root.gotoAndPlay("studio1");
break;
case "321" :
_root.gotoAndPlay("studio1");
break;
case "4321" :
_root.gotoAndPlay("studio2");
break;
// and so on to cover all variations
case "678" :
trace("you selected 678");
break;
}
};
btnSubmit.addEventListener("click", Submit);
////////////reset button///////////////////
this.attachMovie("Button","btnReset",2100,{_x:75, _y:730, label:"Reset"});
var Reset:Object = {};
Reset.click = function(){
for(var n:Number=1; n!=5; n++){
_root["RB_"+n].selected = false;
}
arr = [];
};
btnReset.addEventListener("click", Reset);
-
January 7th, 2008, 12:53 AM #63217Registered User
posts
-
January 7th, 2008, 01:36 PM #64
-
January 8th, 2008, 12:04 AM #65217Registered User
posts
-
March 6th, 2008, 07:35 PM #66
MovieClip instance using getDefinitionByName
Code:public static function getMovieInstance( skinName:String ):MovieClip { var classDef:Object = null; var instance:MovieClip=null; var skin:Object = skinName; if (skin is Class) { return (new skin()) as MovieClip; } try { classDef = getDefinitionByName(skin.toString());//try to find name in system instance = new classDef(); } catch(e:Error) { } //do nothing if (instance == null) { instance = new MovieClip(); } return instance as MovieClip; //return it as a MovieClip }
Description: A function used for returning a movieClip from the fla buy finding it name "getDefinitionByName" .
Parameters:
skinName:String - The name to find.
Returns:
MovieClip - new MovieClip instance of a found reference to the class object or blank movieclip if not found.
Example Usage:
Code:if( mainBgSkin) { mainHolder.removeChild(mainBgSkin); mainBgSkin=null; } mainBgSkin = getMovieInstance( "bgSkinSymbol" ); addChild(mainBgSkin );
-
March 26th, 2008, 03:34 PM #67
Hey everyone - a stupid little snippet, and one I'm sure everyone's come across, but I was looking a while back for a fast way to get the sign of a value, and eventually scratched this down:
How simple does that get, eh? lol, but it's actually helped me out a lot.. Hope I'm passing along something as useful to someone elseCode:function sign(val:Number):int { return (val < 0) ? -1:1; }
-
April 14th, 2008, 06:11 PM #686Registered User
posts
-
May 8th, 2008, 03:05 AM #691Registered User
postsCum shotsCumCum sexCum *** shotCum into *****
How about regular expressions?
Code:var email_pattern: RegExp =/^\w+([\-\w]+)*\w@\w+(([\.\-]\w)*\w+)*\.\w{2,4}$/iLast edited by ddffee1; June 19th, 2008 at 04:22 AM.
-
June 6th, 2008, 12:04 AM #7034Registered User
posts
Wow, is this a joke? Besides the clumsy nature in which its written, it will break if you pass it a negative number, and will also exhibit odd and incorrect behavior if given a non-whole number (you did type it as a Number after all for a function that only accepts natural numbers). Try this:
Code:function factorial(num:int):int { if (num < 1 || !num) return 0; var fact:int = 1; for (var i:int = 2; i <= num; i++) fact *= i; return fact; }
-
June 6th, 2008, 12:12 AM #71
Well that was AS2.
Proud Montanadian
We tolerate living and breathing. And niches.
Name Brand Watches
Maybe getTimer() or TweenMax is the answer to your problem . . .
-
June 6th, 2008, 12:19 AM #7234Registered User
postsOH GOD, MY EYES! That is so, SO bad. And broken, too.Code:function verifyEmail(address:String):Object { if (address.indexOf("@") == -1) { return "Error: Invalid Address - No domain name entered."; } else if (address.indexOf(".") == -1) { return "Error: Invalid Address - No top-level domain entered."; } else if (address.indexOf("@")<5) { return "Error: Invalid Address - Address too short."; } else if (address.lastIndexOf(".")-5<=address.lastIndexOf("@")) { return "Error: Invalid Address - Domain name too short."; } else if (address.charAt(0) == "." || address.charAt(0) == "_" || address.charAt(0) == "-") { return "Error: Invalid Address - Address invalid."; } else if (address.split("@").length != 2) { return "Error: Invalid Address - Too many @s."; } else if (address.indexOf(" ") != -1 || address.indexOf("<") != -1 || address.indexOf(">") != -1 || address.indexOf("(") != -1 || address.indexOf(")") != -1 || address.indexOf("[") != -1 || address.indexOf("]") != -1 || address.indexOf("\\") != -1 || address.indexOf(",") != -1 || address.indexOf(";") != -1 || address.indexOf(":") != -1) { return "Error: Invalid Address - Invalid characters."; } return true; }
Try this for size. This will work with any email you throw at it, and follows all the web standards for a proper email address (unlike the above):
Code://returns true is the email address is valid, false if not. function validateEmail(email:String):Boolean { var regexp:RegExp = /^\w[\w_\.\-\+]*?@\w([\w_\-\+]*?\.)+?[a-zA-Z]+$/; return !(regexp.exec(email) == null); }Last edited by LordMoyne; June 6th, 2008 at 12:26 AM.
-
June 6th, 2008, 12:22 AM #73
Again, AS2.
Proud Montanadian
We tolerate living and breathing. And niches.
Name Brand Watches
Maybe getTimer() or TweenMax is the answer to your problem . . .
-
June 6th, 2008, 12:25 AM #7434Registered User
posts
There are numerous problems with that. It doesn't accept . _ and +, which are valid in all but the domain. It also allows numerals in the domain, which is invalid. It also requires the domain to be between 2 and 4 characters, which is not required.
-
June 6th, 2008, 12:38 AM #7534Registered User
postsMan, these things just get worse and worse. I'm not even going to ask what the deal is with that (255 - 0 + 1).
For comparisons sake, 1,000,000 iterations of my code ran in 750ms. 1 million of yours took nearly 10 seconds.Code:function getRand():uint { return ((Math.floor(Math.random() * 256)<<16) + (Math.floor(Math.random() * 256)<<8) + Math.floor(Math.random() * 256)); }

Reply With Quote
and embarrassment - should have done more testing and with more sleep.




Bookmarks