Showing posts with label Flash. Show all posts
Showing posts with label Flash. Show all posts

Thursday, November 17, 2011

Flash Image smoothing

Sometime we have to resize JPGs in Flash on a "loadMovie" script by making the target scale - just because. However, this usually makes the image jagged and pixelated - hate it!

So let's fix it. I found this here:

import flash.display.*;

function loadBitmapSmoothed(url:String, target:MovieClip) {
// Create a movie clip which will contain our
// unsmoothed bitmap
var bmc:MovieClip = target.createEmptyMovieClip(
"bmc",
target.getNextHighestDepth());

// Create a listener which will notify us when
// the bitmap loaded successfully
var listener:Object = new Object();

// Track the target
listener.tmc = target;

// If the bitmap loaded successfully we redraw the
// movie into a BitmapData object and then attach
// that BitmapData to the target movie clip with
// the smoothing flag turned on.
listener.onLoadInit = function(mc:MovieClip) {
mc._visible = false;

var bitmap:BitmapData = new BitmapData(
mc._width,
mc._height,
true);

this.tmc.attachBitmap(
bitmap,
this.tmc.getNextHighestDepth(),
"auto",
true);

bitmap.draw(mc);
};

// Do it, load the bitmap now
var loader:MovieClipLoader = new MovieClipLoader();
loader.addListener(listener);
loader.loadClip(url, bmc);
}


Then all that is left to do is add:

createEmptyMovieClip("myMC",getNextHighestDepth());
loadBitmapSmoothed("mypic.jpg",myMC);



Thursday, June 24, 2010

Flash Actionscript Tweening

function tween(mc, what, easeType, begin, end, time, then, onWhat) {
if (easeType == 1) {
myEase = Regular.easeInOut;
} else if (easeType == 2) {
myEase = Strong.easeInOut;
} else if (easeType == 3) {
myEase = Regular.easeOut;
} else if (easeType == 4) {
myEase = Strong.easeOut;
} else if (easeType == 5) {
myEase = Regular.easeIn;
} else if (easeType == 6) {
myEase = Strong.easeIn;
} else if (easeType == 7) {
myEase = None.easeNone;
} else if (easeType == 8) {
myEase = Back.easeOut;
}

var myTween:Tween = new Tween(mc, what, myEase, begin, end, time, false);
myTween.onMotionFinished = function() {
if (then != null) {
then.call();
}
//this.yoyo();
};

};

Wednesday, December 16, 2009

My Flash to EXE fullscreen scalling settings

The new version of Flash Player when rendering an EXE document doesn't want to obey the "fscommand" for some reason. I don't know why, I don't care. This works just fine:

fscommand("fullscreen", true);
fscommand("allowscale", false);
fscommand("showmenu", false);
Stage.scaleMode = "showAll";

Tuesday, November 17, 2009

Mute Streaming Audio in Flash

Muting sounds that are streaming in Flash isn't as simple as changing the volume of an object via a "mute" button. But it is surprisingly EASY! I can't believe I didn't see it. AND the movie continues to play and unmuting just brings the sound back in.... duh!

Well, I searched and searched and finally found something. Thanks (http://www.actionscript.org/forums/showthread.php3?t=32982)! I made some simple modifications.

This is my code. I made a MC with 2 frames and buttons in it. In frame 1, a button that calls "mute();" here's the button code for the one that's in frame 1.

on (release) {
nextFrame();
this._parent.mute();
}
And frame 2 has this:

on(release) {
prevFrame();
this._parent.unmute();
}

And here's the code in the root. I could easily make a volume slider that sets the "level" variable, and would then set. But for most stuff, we simply need the sound to be either there... or not.

level = 100;
globalSound = new Sound();
globalSound.setVolume(level);

function mute() {
trace("mute");
//previewaudio.stop();
globalSound.setVolume(0);
}
function unmute() {
trace("unmute");
globalSound.setVolume(100);
}

Enjoy!

Wednesday, October 7, 2009

Flash right-click menu

I've always been looking for a nice and easy Flash right-click menu builder. This one seems extremely straight-foward and EASY!



function calledFunction1() {
trace("calledFunction1");
}

function calledFunction2(){
trace("calledFunction2");
}
MENU = new ContextMenu();
MENU.hideBuiltInItems();
insertAfter = new ContextMenuItem("Call function 1", calledFunction1);
insertBefore = new ContextMenuItem("Call function 2", calledFunction2);

MENU.customItems.push(calledFunction1);
MENU.customItems.push(calledFunction2);
_root.menu = MENU;



Wednesday, March 4, 2009

Flash - Old School Actionscript Tweening

ON the MovieClip itself

/* */
onClipEvent(load) {
mytime = _parent.timeSlower;
mybounce = _parent.bounceSlower;
}
onClipEvent (load) {
physics = [mybounce,mytime];
start_x = this._x;
start_y = this._y;
start_w = this._width;
start_h = this._height;
start_xscale = this._xscale;
start_yscale = this._yscale;
start_a = this._alpha;

xspeed = 0;
yspeed = 0;
aspeed = 0;
wspeed = 0;
hspeed = 0;
xscalespeed = 0;

//this._width = (this._width*1.2);
//this._height = (this._height*1.2);

//this._width = this._width/2;
}
onClipEvent (enterFrame) {
xscalespeed = ((start_xscalespeed-this._xscale)*physics[0])+(xscalespeed*physics[1]);
this._xscale += xscalespeed;

yscalespeed = ((start_yscalespeed-this._yscale)*physics[0])+(yscalespeed*physics[1]);
this._yscale += yscalespeed;

wspeed = ((start_w-this._width)*physics[0])+(wspeed*physics[1]);
this._width += wspeed;

hspeed = ((start_h-this._height)*physics[0])+(hspeed*physics[1]);
this._height += hspeed;

xspeed = ((start_x-this._x)*physics[0])+(xspeed*physics[1]);
this._x += xspeed;
yspeed = ((start_y-this._y)*physics[0])+(yspeed*physics[1]);
this._y += yspeed;
aspeed = ((start_a-this._alpha)*physics[0])+(aspeed*physics[1]);
this._alpha += aspeed;
}
/**/

Still need to establish the "time" and "bounce" variables for consistency across the board.

Thursday, January 29, 2009

Dynamic buttons in Flash using ActionScript 2.0

I am often needing Flash to create dynamic buttons from an Array (or external TXT (text) document). Here's how I do it:

1. Make your button an actual MovieClip on the stage however you want them all to look/work. Create a dynamic text field (center justified - or whatever) within the button with the instance property of "text_txt" for this example. (You can name it whatever you want, but you'll need to change some of the code below).

2. In the library find your MovieClip. Open the Symbol properties dialog.

3. Select the "export of actionscript" check box. Identifier "myButton"... again, for this example only. Click OK.

4. Now return to the stage and in frame one of a layer, I've named my top-most layer "actions". Copy and paste the following:

for(i=0; i
target = this.attachMovie("myButton", "myButton"+i, i, {_x:10, _y:30*i} );
target.text_txt.text = nav[i];
target.myLink = url[i];
trace(myLink);
target.nr = i;
target.onPress = function(){
//getURL(this.myLink);
trace("Hi, I'm "+this._name+" and my number is "+this.nr+". The link is: " + this.myLink);
}
}

With some extra work we can make this a horizontal menu, getting the width of each text box and moving the rest.... I'll post that another time.

5. I created an Array that I want to use for the labels of my buttons. Eventually I will pull these labels from a database table, but for now, paste this info above the previous code.

var nav:Array = Array();

nav[0] = "nav 1";
nav[1] = "nav 2;
nav[2] = "nav 3";
nav[3] = "nav 4";
nav[4] = "nav 5";
nav[5] = "nav 6";
nav[6] = "nav 7";

6. Now we need these links to do something, right? So let's create an Array for our URLs. Paste this array just below the previous but before the button code "for" stuff.

var url:Array = Array();

url[0] = "http://www.adobe.com";
url[1] = "my link 1";
url[2] = "my link 2";
url[3] = "my link 3";
url[4] = "my link 4";
url[5] = "my link 5";
url[6] = "my link 6";


6. Ta da! That's all that is to it.

7. Publish your file.

Wednesday, January 21, 2009

Flash Random Number generator

A little actionscript to get a random number (n) is this case.




low = 0;
high = 360;

function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
return randomNum;
}
for (var i = 0; i < 1; i++) {
var n:Number = randRange(low, high)
trace(n);
}

Tuesday, December 2, 2008

Flash Multiply Error

Flash PNG or any image Multiply Filter error.

I am having trouble with the "multiply filter" in Flash. Evidently, I am not the only one.

Someday, I hope to find an answer.


Here's a guy who posted the SAME issue:
http://www.bitsofstring.org/extra/flash/flashblendingtest.html

Thursday, September 25, 2008

Flash ASCII Code

If you need ASCII characters (+, > , %, etc) this link will give you all the values to put into the text file (txt, php, whatever) for translation to Flash textareas.



Thursday, August 14, 2008

Pause Flash

// sec = number of seconds

function paused(sec) {
stop();
var i = sec - 1;
var t = setInterval(function () {
if (i == 0) {
clearInterval(t);
play();
}
i--;
}, 1000);
}

Then in a frame add:
paused (sec); // change sec to the number of seconds for the pause