adding URL-check to AS file
Hi,
Moved from general Flash forum
I am a newbie using Flash Pro CS5 and have beginner skills in AS3.
I am working on an eLearning lesson and already, with a lot of earlier help of others, and have an Action Script file to use for a white noise animation in a learning lesson.
I need to make a couple of additions but am very unfamiliar with adding script to an Action Script file "package." Specifically, I want to add a URL checking to the Action Script file so that students do not view the Flash movie animation outside of the lesson which contains learning materials and instructions for using the animation.
I would like to add the following script but so far, I have been getting error messages:
if ((this.loaderInfo.url).indexOf("mywebsite. com") == -1)
navigateToURL (new URLRequest ("http://mywebsite.com/default.html"));
else
//run the animation
The current AS3 in the .as file is:
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.utils.getTimer;
import flash.utils.Timer;
public class Main extends Sprite
{
private var viewbmd:BitmapData;
private var workbmd:BitmapData;
private var scaleUp:Matrix;
private var px:Vector.<uint>;
private var timer:Timer;
private var itsNoisy:Boolean;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
viewbmd = new BitmapData(stage.stageWidth, stage.stageHeight, false);
var view:Bitmap = new Bitmap(viewbmd);
addChild(view);
workbmd = new BitmapData(viewbmd.width / 8, viewbmd.height / 8, false);
scaleUp = new Matrix();
scaleUp.scale(8, 8);
itsNoisy = true;
stage.addEventListener(MouseEvent.CLICK, manageNoise);
initNoise();
timer = new Timer(50);
timer.addEventListener(TimerEvent.TIMER, onTick);
timer.start();
}
private function initNoise():void {
var array:Array = [];
for (var i:uint = 0; i < 255; i++) {
array = 0xffffff * (i % 2);
}
workbmd.noise(getTimer(), 0, 255, 7, true);
workbmd.paletteMap(workbmd, workbmd.rect, new Point(0, 0), array, array, array);
px = workbmd.getVector(workbmd.rect);
}
private function onTick(e:Event):void {
flipSomePixels(160);
viewbmd.draw(workbmd, scaleUp);
}
private function flipSomePixels(howMany:int):void {
for (var i:int = 0; i < howMany; i++){
var pxidx:int = Math.floor(Math.random()*px.length);
px[pxidx] = ~px[pxidx]; //bitwise NOT to flip all bits
}
workbmd.setVector(workbmd.rect, px);
}
private function manageNoise(e:MouseEvent):void {
itsNoisy ? timer.removeEventListener(TimerEvent.TIMER, onTick) : timer.addEventListener(TimerEvent.TIMER, onTick);
itsNoisy = !itsNoisy;
}
}
}
If anyone can take a look and please let me know how to add the additional script to check for the URL (please be specific since I am a beginner in scripting):
I have tried everything that I can think of and am stuck.
Thanks in advance for your help.
Kind Regards,
saratogacoach