Search This Blog

Friday, September 25, 2009

Actionscript 2.0 Essentials

 Duplicate MovieClip random postion no OverLap
function shuffle() {
    var noStars:Number = 48;
    var mcStar:MovieClip;
    var aStars:Array = new Array();
    init();
    function init():Void {
        for (var i:Number = 0; i
            mcStar = _root.attachMovie("btn_tt", "drag"+i, i);
            _root["drag"+i].txt.text = _root["btn_text"+i];
            _root["drag"+i].txt.autoSize = "center";
            _root["drag"+i].btn_bg.width = _root["drag"+i].txt.width+10;
            aStars.push(mcStar);
            randomPlacement();
        }
    }
    function randomPlacement():Void {
        mcStar._x = 100+Math.floor(Math.random()*900);
        mcStar._y = 250+Math.floor(Math.random()*330);
        for (var j:Number = 0; j
            if (mcStar.hitTest(aStars[j]) && mcStar != aStars[j]) {
                randomPlacement();
            }
        }
    }
}
shuffle();



find and replace script

function searchAndReplace(holder, searchfor, replacement) {
temparray = holder.split(".");
holder = temparray.join(",");
return (holder);
}


acceleration = round(_root.sliders.accelSlider.value*5, 1)+1;
ac = String(acceleration);
myreplace2 = searchAndReplace(ac);
accelerationv = myreplace2;



Round of number decimal places

function round(number, decimalPlaces) {
var multiplier = Math.pow(10, decimalPlaces);
var rounded = Math.round(number*multiplier)/multiplier;
if (isNan(number)) {
rounded = 0;
}
// end if
return (rounded);
}


acceleration = round(_root.sliders.accelSlider.value*5, 1)+1;


////////////////////////////////////////////////////////////////////
removing HTML Tag inText field


  1. myInfo="With the European Championships just a year away, places in the England squad are hot property! If you were Sven who would you be putting into the Squad? Here at Hy-PRO we are giving away five of our official England signature footballs, which include authentic, printed signatures of the whole England squad. To enter all you have to do is suggest to us which 18 players you think Sven should put into his Squad. This must include at least 2 goalkeepers. The first five entries picked out the hat will win.";

  2. var temp="";

  3. var itsHtml = false;

  4. for(i=0; ilength; i++){

  5.     if(myInfo.charAt(i)=="<"){

  6.         itsHtml = true;

  7.     }

  8.     if(!itsHtml){

  9.         temp += myInfo.charAt(i);

  10.     }

  11.     if(myInfo.charAt(i)==">"){

  12.         itsHtml = false;

  13.     }

  14. }

  15. trace(temp);

/////////////////////////////////////////////////////////////////////////
Line To two dots

// place the two handles for the endpoints
_root.attachMovie("roundHandle", "h1", 5);
//_root.attachMovie("roundHandle", "h2", 6);
h1._x = 50;
h1._y = 150;
/*h2._x = 250;
h2._y = 150;*/
// create a clip to draw to
_root.createEmptyMovieClip("mc", 1);
// this function redraws the line
function draw() {
// clear out the old line
mc.clear();
// set our line style
mc.lineStyle(1, 0x000000);
// draw the line based on handle locations
mc.moveTo(h1._x, h1._y);
mc.lineTo(h2._x, h2._y);
}
// call draw every 25 milliseconds
setInterval(draw, 25);



/////////////////////////////////////////////////////////
Embed Font

createTextField("dynamic_txt", 2, 10, 40, 150, 30);
dynamic_txt.text = "Here's more text";
dynamic_txt.embedFonts = true;
var emphatic:TextFormat = new TextFormat();
emphatic.size = 16;
emphatic.font = "Font 1";
dynamic_txt.setTextFormat(emphatic);


////////////////////


For MP3 Play pause stop
////////////////////////sound/////////////////////////
//
pause_btn_voi.onPress = function() {
pause_btn_voi._visible = 0;
play_btn_voi._visible = 1;
_root.p1._visible = 0;
if (pause != true) {
playing = false;
paused = true;
stopped = false;
_root.myConditionText = "Paused";
myMusic_vPosition = _root.myMusic_v.position/1000;
_root.myMusic_v.stop();
}
};
pause_btn_voi.onRollOver = function() {
_root.p1._visible = 1;
};
pause_btn_voi.onRollOut = function() {
_root.p1._visible = 0;
};
//
play_btn_voi.onPress = function() {
pause_btn_voi._visible = 1;
_root.p2._visible = 0;
this._visible = 0;
if (playing != true) {
playing = true;
paused = false;
stopped = false;
_root.myConditionText = "Playing";
_root.myMusic_v.start(myMusic_vPosition, 0);
}
_root.myMusic_v.onSoundComplete = function() {
_root.pause_btn_voi._visible = 0;
_root.play_btn_voi._visible = 1;
_root.myCondition.textColor = 0x00FF00;
_root.myConditionText = "Completed";
};
};
play_btn_voi.onRollOver = function() {
_root.p2._visible = 1;
};
play_btn_voi.onRollOut = function() {
_root.p2._visible = 0;
};
//
stop_btn_voi.onPress = function() {
pause_btn_voi._visible = 0;
play_btn_voi._visible = 1;
_root.p3._visible = 0;
playing = false;
paused = false;
stopped = true;
_root.myConditionText = "Stopped";
_root.myMusic_v.stop();
myMusic_vPosition = 0;
myMusic_vPositionText = 0;
stopAllSounds();
};
stop_btn_voi.onRollOver = function() {
_root.p3._visible = 1;
};
stop_btn_voi.onRollOut = function() {
_root.p3._visible = 0;
};
//
_root.vol_cont = function() {
if (stopped != true) {
_root.myMusic_vDurationText = _root.myMusic_v.duration/1000;
_root.myMusic_vPositionText = _root.myMusic_v.position/1000;
_root.myMusic_rDurationText = _root.myMusic_r.duration/1000;
_root.myMusic_rPositionText = _root.myMusic_r.position/1000;
}
_root.myMusic.setVolume(volu);
};
//
myMusic_v = new Sound(myMusicMc);
myMusic_r = new Sound(myMusicMc1);
load_sound = function () {
_root.myConditionText = "Playing";
myMusic_v.loadSound(pathSndFile, true);
_root.myMusic_v.onSoundComplete = function() {
_root.pause_btn_voi._visible = 0;
_root.play_btn_voi._visible = 1;
pause_btn_voi._visible = 0;
play_btn_voi._visible = 1;
_root.p3._visible = 0;
playing = false;
paused = false;
stopped = true;
_root.myConditionText = "Stopped";
_root.myMusic_v.stop();
myMusic_vPosition = 0;
myMusic_vPositionText = 0;
_root.myConditionText = "Completed";
};
};
//end Sound
load_sound();

Drag and Drop

l = 100;
t = 100;
r = 750;
b = 480;
var count:Number = 0;
////////////shuffle/////////////////
function shuffle() {
var pos:Array = new Array();
var pos1:Array = new Array();
for (var i = 0; i<13; i =" 0;" j =" pos.splice(random(pos.length)," i =" 0;" _y =" eval(" yp="pos1[i].yp;" i =" 1;" index =" i;" index =" i;" xp =" eval(" yp =" eval(" onpress =" function()" onrelease =" eval(" onreleaseoutside="function" dr =" eval(this._droptarget);" index ="=" _visible =" 0;" _alpha =" 100;" enabled =" false;" _x =" this.xp;" _y =" this.yp;" _x =" this.xp;" _y =" this.yp;" count ="=" onpress =" function()" i =" 0;" _x =" eval(" _y =" eval(" enabled =" true;" _visible =" 1;" count =" 0;" size="4" style="color: rgb(255, 0, 0);">To rename the Objects name in the library JSFL

var NAME = "Mc_GR";
var items = fl.getDocumentDOM().library.items;
var itemNum = items.length;
for (var i = 0; i < name =" NAME">

No comments:

Post a Comment