Please read first about snippets and how it use in FlashDevelop.
Here i want to tell you about aSnippet. aSnippet enables you to keep all of your frequently used code snippets (As3, As2, Js, PHP, HTML, MXML…) in one place that’s accessible from any computer. Also //aSnippet is also available via any browser, no [...]
Please look to the simple code below:
function myFunction(a:Number, b:Number):Number
{
var rez:Number;
rez=a+b;
return (rez);
}
var sum1:Number=myFunction(1,2);
var sum2:Number=myFunction(4,3);
var sum3:Number=myFunction(10,5);
trace(sum1);
trace(sum2);
trace(sum3);
There you can see parameters (a:Number, b:Number) of function myFunction. If you will use it then you can change your variable ‘rez’ any time;) Do it with:
var sum1:Number=myFunction(1,2);
var sum2:Number=myFunction(4,3);
var sum3:Number=myFunction(10,5);
As i right clear this is the main idea of function parameters:)
Here result [...]
I saw word ‘return’ a lot in the end of function but just now i find info what does it mean:)
So i created simple code:
function myFunction()
{
var a:int=2;
var b:int=3;
var c:int;
c=a+b;
return (c);
}
var myVariable:int=myFunction();
trace(myVariable);
Here i created simple function myFunction and in the end of body myFunction() you can see command ‘return (c)’. So its mean i want get [...]
Please create your flash file in flash IDE(for example draw flash site).
Then add button with instance name ‘my_btn’(after clicking to this button your flash work will be on full screen).
Then add code :
my_btn.addEventListener(MouseEvent.CLICK, fullScreen);
function fullScreen(event:MouseEvent):void
{
stage.displayState=StageDisplayState.FULL_SCREEN;
}
Then open Preview Settings and make like this:
Source:
full_screen
import fl.controls.RadioButtonGroup;
rb1.label=”C++”;
rb2.label=”ActionScript 3.0″;
rb3.label=”ActionScript 2.0″;
rb4.label=”Java”;
rb5.label=”Pascal”;
answer_btn.label=”Select Answer”;
var radioGroups1:RadioButtonGroup=new RadioButtonGroup(”Question1″);
//rb1.selected=true;
rb1.group=radioGroups1;
rb2.group=radioGroups1;
rb3.group=radioGroups1;
rb4.group=radioGroups1;
rb5.group=radioGroups1;
answer_btn.addEventListener(MouseEvent.CLICK, checkAnswer);
function checkAnswer(event:MouseEvent):void {
if (radioGroups1.selection==null) {
answer_txt.text=”Need choose any answer!”;
return;
}
if (radioGroups1.selection.label==”ActionScript 3.0″) {
answer_txt.text=radioGroups1.selection.label+” is correct answer!”;
} else {
answer_txt.text=radioGroups1.selection.label+” is wrong answer!”;
}
}
Source:
quiz
var my_box:Box = new Box();
addChild(my_box);
var myTimer:Timer = new Timer(1000);
myTimer.addEventListener(TimerEvent.TIMER, drawBox);
function drawBox(event:TimerEvent) {
my_box.x=my_box.x+10;
this.graphics.beginFill(0xff0000);
this.graphics.drawCircle(event.target.currentCount*10,100,10);
}
myTimer.start();
var my_star:Star = new Star();
addChild(my_star).y=150;
var lastTime:int = getTimer();
addEventListener(Event.ENTER_FRAME, animateStar);
function animateStar(event:Event) {
var timeDiff:int = getTimer()-lastTime;
lastTime += timeDiff;
my_star.x += timeDiff*.02;
}
Source:
Timer
var startTime:int = getTimer();
addEventListener(Event.ENTER_FRAME, myStopwatch);
function myStopwatch(event:Event) {
var timePassed:int = getTimer()-startTime;
var seconds:int = Math.floor(timePassed/1000);
var minutes:int = Math.floor(seconds/60);
seconds -= minutes*60;
var timeString:String = minutes+”:”+String(seconds+100).substr(1,2);
stopwatch_txt.text = timeString;
}
Source:
Stopwatch
stop();
addEventListener(Event.ENTER_FRAME, loading);
function loading(event:Event)
{
var mcBytesLoaded:int=this.root.loaderInfo.bytesLoaded;
var mcBytesTotal:int=this.root.loaderInfo.bytesTotal;
var mcKLoaded:int=mcBytesLoaded/1024;
var mcKTotal:int=mcBytesTotal/1024;
my_txt.text=”Loading: “+mcKLoaded+”K of “+mcKTotal+”K”;
if (mcBytesLoaded>=mcBytesTotal)
{
removeEventListener(Event.ENTER_FRAME, loading);
gotoAndStop(2);
}
}
Source:
Preloader2
addEventListener(Event.ENTER_FRAME, checkCollision);
function checkCollision(event:Event)
{
if (bone_mc.hitTestPoint(mouseX,mouseY,true))
{
pointText.text=”hitTestPoint: Overlaps”;
} else
{
pointText.text=”hitTestPoint: No Overlaps”;
}
dog_mc.x=mouseX;
dog_mc.y=mouseY;
if (dog_mc.hitTestObject(bone_mc))
{
objectText.text=”hitTestObject: Overlaps”;
} else
{
objectText.text=”hitTestObject: No Overlaps”;
}
}
Source:
DetectinCollisions2
Mouse.hide();
addEventListener(Event.ENTER_FRAME, myCursor);
my_cursor.mouseEnabled = false;
function myCursor(event:Event) {
my_cursor.x = mouseX;
my_cursor.y = mouseY;
}
Source:
Custom_Cursor