0

I want to prevent users from using webcam emulators, I have done that in AS2 by using senocular's function, but I can't make it work in AS3,so, here is the old version by senocular , and I would like to do the same in AS3, tried using indexOf but doesn't work, I need to find at least the first 4 characters of the string and compare them to the item inside the array in AS3!

String.prototype.startsWith = function(str){ return !this.indexOf(str); } 

here is what I want to do:

var bannedDevices = new Array("FakeCam","SplitCam","Phillips Capture Card 7xx","VLC"); var myDeviceName = "SplitCam v1.5"; //"Splitcam" in bannedDevices should trigger this; if (myDeviceName.indexOf(bannedDevices)){ trace("banned device"); } 

Thanks for the help !

2 Answers 2

2

OK, I leave my previous answer for history. Now that i've understood what you want:

public function FlashTest() { var bannedDevices:Array = new Array("FakeCam","SplitCam","Phillips Capture Card 7xx","VLC"); var myDeviceName:String = "SplitCam v1.5"; //"Splitcam" in bannedDevices should trigger this; trace(startsWith(myDeviceName, bannedDevices, 4)); } /** * @returns An array of strings in pHayStack beginning with pLength first characters of pNeedle */ private function startsWith(pNeedle:String, pHayStack:Array, pLength:uint):Array { var result:Array = []; for each (var hay:String in pHayStack) { if (hay.match("^"+pNeedle.substr(0,pLength))) { result.push(hay); } } return result; } 
Sign up to request clarification or add additional context in comments.

Comments

1

Your need is not very clear... Here is a function which returns every string from an array that starts with the given string.

public function FlashTest() { var hayStack:Array = ["not this one", "still not this one", "ok this one is good", "a trap ok", "okgood too"]; trace(startsWith("ok", hayStack)); } /** * @returns An array of strings in pHayStack beginning with the given string */ private function startsWith(pNeedle:String, pHayStack:Array):Array { var result:Array = []; for each (var hay:String in pHayStack) { if (hay.match("^"+pNeedle)) { result.push(hay); } } return result; } 

2 Comments

Hello Kodiak, thanks for the reply, but it does not work as I need it to, if i add something to "ok" like: "ok v2.4" then it won't trace anything.
You need to define what you need more precisely, here my function returns the strings which starts with EXACTLY the given param...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.