Tag Archive for as

Clone array (AS3)

var a:Array = [1, 2, 3, 4, 5];
var b:Array;

//clone a:
b = a.map(function(e:*, ...r):*{ return e });

/*
"...r" is a "rest" and stands for the two more arguments, the function in map(f:Function, target:Object = null) needs.

Full function would be: function (element:*, index:int, array:Array):*{return e};
*/

source

AS Flash Lite1.1 携帯のボタンフォーカスを消す

_focusrect = false ;//ボタンフォーカスを消す

source

AS Flash Lite1.1 EnterFrameでローディングバー

if (_framesloaded >= _totalframes) {
gotoAndPlay("default");
} else {
tellTarget("loader") {
_xscale = (_framesloaded/_totalframes)*100;
}
}

source

AS Flash Lite1.1 入れ子のMCに指示を送る(tellTarget)

// パスの書き方に注意
// /:はrootの変数currentImage

tellTarget("/box_mc/images_mc"){
gotoAndStop(/:currentImage);
}

source

AS Flash Lite1.1 MCのダイナミックテキストにテキストを送る

// root以下にbox_mcを配置して、その中に変数=numdisplayのダイナミックテキストを配置
tellTarget("/box_mc"){
numdisplay = /:collectionLabel add ": " add /:currentImage;
}

source

AS Flash Lite1.1 決定キーを押して実行するボタンアクション

on (keyPress "<Enter>") {
// 実行したいアクション
}

source

AS2 リサイズ時の処理 フルFLASHでのリサイズ

Stage.align = "TL";
Stage.scaleMode="noScale";
Stage.addListener(this);
this.onResize = function() {
/*	リサイズ時の処理〜〜*/
head_shadow_mc._width = Stage.width;
underwhiteline_mc._width = Stage.width;
movie_mc._x = Stage.width/2 - movie_mc._width/2;
scroll_mc._x = Stage.width/2 - scroll_mc.mask_mc._width/2;
};
this.onResize();

source

MP3 Player

import er4d.util.Delegate;
import er4d.transitions.Tween;

class panik.PlayerMp3 extends MovieClip
{

private var play_btn:MovieClip;
private var pause_btn:MovieClip;
private var timeline:MovieClip;
private var timeline_bg:MovieClip;

private var songTrack:Sound;
private var loaded:Boolean;
private var	_src:String;

private var track_position:Number;
private var track_duration:Number;

private var loading_int:Number;
private var playing_int:Number;

function PlayerMp3()
{
loaded = false;
}

// INIT
public function set src(_src:String) {
this._src = _src;
loaded = false;
}
public function get isLoaded() {
return loaded;
}
public function loadMP3 (autoplay:Boolean) {
songTrack = new Sound();
songTrack.onLoad = Delegate.create(this, songLoaded, autoplay);
songTrack.loadSound(_src, true);
loaded = true;
loading_int = setInterval(this, "checkLoadingProgress", 100);
// CONTROL
timeline._width = 0;
play_btn.onPress = Delegate.create(this, startSound);
pause_btn.onPress = Delegate.create(this, stopSound);
if(autoplay) enablePlayBtn (false);
else enablePlayBtn (true);

}
// SOUND CONTROL
public function stopSound () {
songTrack.stop();
enablePlayBtn (true);
}
public function startSound (n:Number) {
// play
if (!n || songTrack.position == songTrack.duration) n = 0;
songTrack.start(n);
enablePlayBtn (false);
}

public function lock() {
this._x += 5000;
play_btn.enabled = pause_btn.enabled = false;
}
public function unlock() {
this._x -= 5000;
play_btn.enabled = pause_btn.enabled = true;
}

// PRIVATE

// watch song loading
private function checkLoadingProgress () {
var numBytesLoaded:Number = songTrack.getBytesLoaded();
var numBytesTotal:Number = songTrack.getBytesTotal();
var numPercentLoaded:Number = Math.floor(numBytesLoaded / numBytesTotal * 100);
}

// song loaded
private function songLoaded (autoplay:Boolean) {
// play stop
if(!autoplay) stopSound(); else
clearInterval(loading_int);
playing_int = setInterval(this, "checkPlayingProgress", 100);
track_duration = songTrack.duration/1000;
}
private function checkPlayingProgress () {
track_position = songTrack.position/1000;
var track_percent:Number = track_position / track_duration * 100;
if(songTrack.position == songTrack.duration) stopSound();
timeline._width = timeline_bg._width * track_percent / 100;
}

private function enablePlayBtn (b:Boolean){
if (b) {
Tween.prop(play_btn, "_alpha", 100);
play_btn.enabled = true;
Tween.prop(pause_btn, "_alpha", 30);
pause_btn.enabled = false;
} else {
Tween.prop(play_btn, "_alpha", 30);
play_btn.enabled = false;
Tween.prop(pause_btn, "_alpha", 100);
pause_btn.enabled = true;
}
}

}

source

scrollmc

/*
* _scrollmc( mc:MovieClip, mask:MovieClip )
*
* Rend un clip scrollable comme un champ texte
*
* 01/06/05 - Philippe
*
*/
_global._scrollmc = function(mc, mask, scroll_track, scroll_bar) {
trace(mc+", "+mask);
// evenements
ASBroadcaster.initialize(mc);

// proprietes
mc.setMask(mask);
mc.mask = mask;
mc.oy = mc._y;
mc.scroll = 1;
mc.bottomScroll = mask._height;
mc.maxscroll = mc._height-mask._height;

mc.scroll_track = scroll_track;
mc.scroll_bar = scroll_bar;
scroll_bar.oy = scroll_bar._y;
scroll_bar._height = (scroll_track._height * mask._height) / mc._height;

//***********************  scroll avec la bar
scroll_bar.mc = mc;
scroll_bar.scroll_track = scroll_track;
scroll_bar.scroll_bar = scroll_bar;
scroll_bar.onRelease = function(){ delete this.onEnterFrame; }
scroll_bar.onReleaseOutside = scroll_bar.onRelease;
scroll_bar.onPress = function(){
this.mouse_oy = _root._ymouse - this._y;
trace(this.mouse_oy);
scroll_bar.onEnterFrame = function(){
this._y += ( Math.min(Math.max(_root._ymouse-this.mouse_oy, this.scroll_track._y) , this.scroll_track._y + this.scroll_track._height - this._height) - this._y ) * .5;
var new_scroll = ((this._y - this.scroll_bar.oy) * this.mc.maxscroll) / (this.scroll_track._height-this._height);
this.mc.scroll = new_scroll;
}
}

// reactivite de la propriete scroll
mc.addProperty("scroll",
function() {
return Math.min( Math.max(1,this.scroll), this.maxscroll);
},
function(value) {
// verification valeur
value = Math.round(value);
value = Math.min( Math.max(1,value), this.maxscroll);
if (value == this.scroll) return;
// maj
this.scroll = value;
// scrollbar
var new_scroll_bar_y = this.scroll_bar.oy + Math.round(this.scroll * (this.scroll_track._height-this.scroll_bar._height) / this.maxscroll);
this.scroll_bar._y = new_scroll_bar_y;
// /scrollbar
this._y = this.oy-value;
this.maxscroll = Math.max(1, this._height+4 - this.mask._height);
this.bottomScroll = value + this.mask._height;
this._y = this.oy-value;
// retour
this.broadcastMessage("onScroller", this);
}
)

trace(mc.scroll+" "+mc.maxscroll);
}

source

FireFox wmode input fix

//util.FirefoxWmodeFix.fix(field);

class util.FirefoxWmodeFix {

// [lettre écrite sous FF, bonne lettre, condition]
public static var  FRENCH_KEYBOARD:Array = [
["&", "1", Key.SHIFT],
["é", "2", Key.SHIFT],
[""", "3", Key.SHIFT],
["'", "4", Key.SHIFT],
["(", "5", Key.SHIFT],
["-", "6", Key.SHIFT],
["è", "7", Key.SHIFT],
["_", "8", Key.SHIFT],
["ç", "9", Key.SHIFT],
["à", "0", Key.SHIFT],

["<", "?", Key.SHIFT],
[":", ".", Key.SHIFT],
["!", "§", Key.SHIFT],
["ù", "%", Key.SHIFT],
["$", "£", Key.SHIFT],
["<", ">", Key.SHIFT],

[""", "#", Key.ALT],
["'", "{", Key.ALT],
["(", "[", Key.ALT],
["-", "|", Key.ALT],
["è", "", Key.ALT],
["_", "", Key.ALT],
["ç", "^", Key.ALT],
["à", "@", Key.ALT]
]

public static var USED_KEYBOARD:Array

public static function fix(_field:TextField)
{
if(!USED_KEYBOARD) USED_KEYBOARD = FRENCH_KEYBOARD
_field.addListener(FirefoxWmodeFix)
_field.textLength = _field.text.length
}

private static function onChanged(_field):Boolean
{
// si on supprime une lettre, on ignore
if (_field.textLength > _field.text.length) {
_field.textLength = _field.text.length
return false
}else {
_field.textLength = _field.text.length
}

var index = Selection.getBeginIndex()
var newLetter = _field.text.substr(index - 1, 1)

for (var i:Number = 0; i <USED_KEYBOARD.length ; i++) {
if (USED_KEYBOARD[i][0] == newLetter) {
if (Key.isDown(USED_KEYBOARD[i][2])) {
_field.text = _field.text.substr(0, index - 1) + USED_KEYBOARD[i][1] + _field.text.substr(index)
return true
}
/* ---===CAPSLOCK ne marche tout simplement pas sur firefox ===---
*
if (USED_KEYBOARD[i][2] == Key.CAPSLOCK && Key.isToggled(Key.CAPSLOCK) ) {
_field.text = _field.text.substr(0, index - 1) + USED_KEYBOARD[i][1] + _field.text.substr(index)
return true
}
*/
}
}

}

}

source