Making A Color Tinter... Which Class Do I Extend?
Hi everybody,
I've got some code that will change the color and tint of an object and return the hex value of the new color. I am trying to make a custom class out of the code and I'm not sure which class this color tinter should extend. Should that be the color class?
Also, how do I go about determining the class to extend when I want to create new classes?
thanks!
-brian
ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 06-24-2008, 10:52 PM
View Complete Forum Thread with Replies
Sponsored Links:
When Making A Document Class Should You Extend MovieClip Or Sprite?
When creating a project with a Document Class should your Document Class extend MovieClip or Sprite?
It seems that if your Fla uses the timeline and contains more than a single frame you'll need to extend MovieClip.
If your fla uses only one frame Sprite might be the better choice. But, are there cases where you might want to use MovieClip still?
Any project could be built around either base Class, MovieClip or Sprite, is one a better choice than the other? It seems MovieClip uses more memory, but is this enough of an issue to make it a best practice?
I'm just getting up to speed with this AS3 stuff and was looking for some thoughts on the subject.
View Replies !
View Related
Tween Class In Custom Extend MovieClip Class
I want to use the tween prototype in a custom class that extends MovieClip. I am already including "lmc_tween.as" in my root and I have already replaced the "MovieClip.as" file in my flash directory with the one from the shared/Zigo directory. However, I still get compiler errors if I try to include "lmc_tween.as" in the class file, or without the include in the class it will compile but the tween prototype will not work in the custom class. Does anyone know how to fix this?
View Replies !
View Related
AS3 Class Extend
Hi everyone,
Been using classes since AS2.
Started a new project in AS3 has my first approach to the new script. One
thing that confuses me is that every single example of a class in the help
panel is by extending the class to a sprite, movieclip and so on. I compare
this with the AS1/AS2 "prototype":
MovieClip.prototype.setRGB = function (color) {
(new Color(this)).setRGB (color);
};
MovieClip.prototype.getRGB = function () {
return (new Color(this)).getRGB();
};
Doesn't the extend approach overload memory?
- Let's say I need a heavy class to personalize a button that is used
only once on the entire project and I extend it to a Sprite. Wont other
sprites used in the same project be heavier because they now have more
properties and methods available because of the extend?
Regards
View Replies !
View Related
How To Extend A PHPObject Class
hello,i wrote the flashObject class as follows:[code]
Code:
class flashObjects extends PHPObject {
//descrive il tipo dell'oggetto
private static var tipi:Array= new Array("router","linea","oggetto","cursore","segnaposto","gruppo","proprietŕ","contenitore");
private var tipo:String;
//parte router
private var id:Number;
private var sid:String;
private var colore:String;
ETC....
...
.....
but flash gives me the following error
**Errore** C:document_rootprove2004novembrephpobjectsfla shObjects.as: Linea 1: Impossibile caricare la classe 'PHPObject'.
class flashObjects extends PHPObject {
Totale errori ActionScript: 1 Errori segnalati: 1
View Replies !
View Related
Extend MovieClip Class
I would like to write some clips, but it seems do not work.
my test.as file:
class test extends MovieClip {
function test() {
this.lineStyle(1, 0xff0000, 100);
this.moveTo(50,50);
this.lineTo(111,111);
}
}
code in first frame script:
var aline;
aline = new test();
stop();
Why the clip does not draw anything!?
But if i modify the class definition as follows:
class test extends MovieClip {
var mc;
function test() {
this.mc = _root.createEmptyMovieClip( "mc1", 10);
this.mc.lineStyle(1, 0xff0000, 100);
this.mc.moveTo(50,50);
this.mc.lineTo(111,111);
}
}
evrything is ok.
So, must be create a property and assign a new mc to it,
or it possible to use simply the this. object for drawing ?
Thanks if someone could help.
View Replies !
View Related
Extend MovieClip Class
I want to add a property to the MovieClip class that tells me if the object is draggable or not.
I tried to do this:
Code:
class MovieClip extends MovieClip
{
public var _draggable:Boolean;
}
But this doesn't work.
I tried to add:
Code:
class MovieClip extends MovieClip
{
public var _draggable:Boolean;
this.prototype._draggable = true;
function isDraggable():Boolean
{
return _draggable;
}
}
But it still doesn't work.
What I need to write?
View Replies !
View Related
How To Extend Movieclip Class ?
OK, I understand that I could create a separate *.as file that contain within it drawing functions to draw a shape out and in that class create within it static variable or just plain public variables for example each "Player" object have a direction, speed and such.
It would be no problem if the player is just merely objects that can be drawn with codes.
But...what if it's an image ?
I would import the image in flash, make it into a movie clip, give the clip a class name through the "Linkage" option and now I have the "Player" Class with the imported image I need....it's all good...but I don't want the "Player" class to just contain an image, I want to give it internal properties.
I presume I could do things like these in the first frame of the timeline:
ActionScript Code:
class Player_with_properties extends Player
{
public var PlayerDirection:int = 0;
public var PlayerSpeed:int = 0;
public function Player_with_properties()
{
trace("Constructor Initialized.");
}
}
But nooooo...Actionscript 3 says "Classes must not be nested.".
All I hear is, Ha Ha Ha from the Actionscript three....
So how do I create a class with image and properties ?
View Replies !
View Related
Model/Class To Extend XML
I'm a newbie to Flex 3/Actionscript, but have done OOP before.
My flex3 application downloads XML in e4x format from my web server, and and is left as a bindable XML object locally in my flex3 application. My visual objects then bind to various aspects of the XML object to display the data that I want.
My simple program is getting more complicated, and I'd like to extend the XML object and add some functions to it, so I can keep the code that manipulates the XML object separate from my base application. Lets call this new object LoginXML.
Can I please get an example of how to extend the XML object in flex3/as3 to create my own custom object with it's own functions. Part of my XML looks like
<nodes>
<node id="1">A</node>
<node id="2">B</node>
<node id="3">C</node>
</nodes>
and I'd like to make a function that outputs an Array of of the data and attributes of this XML section.
Sorry if my vocabulary is off Thanks.
--matt
View Replies !
View Related
Extend Array Class
I am trying to extend the array class.
In my fla I have this:
ActionScript Code:
var myArr:Array = new Array('1','2','3');
myArr.implode(myArr,';');
And my class looks like this:
ActionScript Code:
package{
import Array;
public class Array extends Array{
public var str:String = '';
public function implode(arr:Array, sep:String):String{
for(var i:int=0;i<arr.length;i++){
str += arr[i].toString()+sep;
}
return str;
}
}
}
When I run it, I get this:
Quote:
1113: Circular type reference was detected in Array.
How can I fix that?
View Replies !
View Related
I Dont Want To My Class To Extend Anything?
Hi all,
I've been struggling with this for a while and figured it would be better to seek some advice from the kirupa forums as you guys have much more knowledge of as3 than me.
I am trying to build a simple debug class so I can debug remotely on projects I create. I got my class working using the singleton pattern so that it is only instantated once and it will trace fine, but when I try to add a TextField to the stage I get errors. I can't use addChild unless the class extends a DisplayObjectContainer, but if my class extends anything it throws an error.
The basic code is below for your thoughts? thanks?
Code:
package
{
import flash.display.DisplayObjectContainer
import flash.text.TextField;
public class Debug extends DisplayObjectContainer
{
private static var VERSION:String = "0.1";
private static var _instance:Debug;// enforce singleton pattern Debug instance
private var _textField:TextField;
// static function to trace to debugger console
public static function write(args)
{
if(_instance == null)
{
_instance = new Debug(arguments.callee);
}
// output arguments
trace(arguments);
// :TODO: send the arguments to the console
}
public function Debug(caller:Function = null)
{
if(caller != Debug.write)
{
throw new Error("Debug is a singleton pattern class, use write() instead");
}
if(Debug._instance != null)
{
throw new Error("Only one Debug instance should be instantiated");
}
// initialize the console
createConsole();
}
private function createConsole():void
{
// create Debug console here
trace("*** New Debugger - " + VERSION + " ***")
// :TODO: create the textfield and console
this._textField = new TextField();
this._textField.width = 200;
this._textField.height = 200;
//addChild(this._textField);
}
}
}
View Replies !
View Related
This Class Only Loads XML...what Should It Extend?
I have a class which allows the document class to say:
var mynewxml:XMLCLASS = new XMLCLASS("xmlfile.xml", newsTextField);
All that class does is load the file and put its contents into newsTextField. I have it currently extending Shape, to simplify it the most, I'm not sure what to extends to make Flash know its super simple and all it does is load an xml file and place the text.
*seems like extends Object keeps the filesize down the most. But I thought object was the biggest thing to inherit, and extending Shape adds 0.06KB to the size.
View Replies !
View Related
Extend TextField Class
I've made a lot f search on this subject and got no answers until now.
I've developed a class to extend the TextField Class, this is a simple class that checks if a textfiled is selected (focus) and cleans default text from it:
ActionScript Code:
class clean_txt extends TextField {
/*
* constructor
*/
private function clean_txt() {}
/*
* function checks if onSetFocus exists if true - cleans textfield
*/
public function remove_txt() {
this.text = "insert your name here";
this.onSetFocus = function () {
this.text = "";
}
}
}
No my problem is to assing the clas to a text field without the use of ptotorype.
I have this code on the movie:
ActionScript Code:
this.createTextField("name_txt", 1, 10, 10, 200, 20);
this.name_txt.background = true;
this.name_txt.border = "1px";
this.name_txt.type = "input";
name_txt.remove_txt(); //this should work now :(
//
Using:
ActionScript Code:
name_txt.__proto__ = clean_txt.prototype;
the class works fine but prototype is bad use.
Any opinions on this subject?
View Replies !
View Related
How To Best Extend A Static Class To A Dynamic
i wanted to create a Label and attach another variable to it (called "link") and make it a button. However Label is not a dynamic class so i decided to do this:
ActionScript Code:
package {
import flash.display.Sprite;
import flash.display.Shape;
import flash.events.MouseEvent;
import flash.text.TextField;
public class DynamicLabel extends Sprite {
public var link:String;
public function DynamicLabel(_title:String, _link:String) {
//bg
var _bg = new Shape();
_bg.graphics.beginFill(0x888888);
_bg.graphics.drawRect(0, 0, 100, 15);
_bg.graphics.endFill();
this.addChild(_bg);
//text
var title:TextField = new TextField();
title.text = _title;
this.addChild(title);
//link
this.link = _link;
this.addEventListener(MouseEvent.CLICK, clickHandler);
this.buttonMode = true;
}
private function clickHandler(e:MouseEvent):void
{
trace(e.target.link);
}
}
}
However when i run it and click on the "DynamicLabel" object (when the "clickHandler" function in executed) i get this error:
Code:
Property link not found on flash.text.TextField
i want to property "link" to be a part of my class, my object. Why does it look for it in the TextField?
Any workaround is greatly appreciated too All i'm trying to do is make dynamic buttons...
View Replies !
View Related
AS3.0: How To Extend A Class That Extends MovieClip
When I try to set the base class of a library symbol to a class that doesn't DIRECTLY extend MovieClip, but instead extends another class that DOES extend MovieClip, it's disallowed, saying, "The class 'Whatever' must subclass 'flash.display.MovieClip' since it is linked..."
Is this just a validation bug in the property windows, only checking one class deep into the inheritance hierarchy? Because the specified class does extend MovieClip, just two levels in instead of one. Is there a fix for this? Or must library symbols always directly extend MovieClip? If so, why?
View Replies !
View Related
Creating A Class To Extend Math
i have a function that i wrote in flash mx, and now that i'm using flash mx 2004, i'm going to have to use a class.
the function is like this:
ActionScript Code:
//as 1.0:function formatNumber(numberToFormat, decimalPlaces) {//}
how would i format that to put it into a class that extends the Math setion of as 2.0?
View Replies !
View Related
Cant Extend Web Service Connector Class
hello there, thanks for checking this. I am trying to extend the WebServiceConenctor class to make a class that checks a web service at set intervals and has some other functionality. I want to set the properties of the object in the constructor but I cant get it to work, also I want to be able to trigger the webservice from methods within the Check class but I think I have the syntax wrong.
If anyone could let me know what I'm doing wrong I would be really grateful. Thanks
ActionScript Code:
class Check extends WebServiceConnector { var active:Boolean; //interval vars private var checkInterval:Number; private var checkFreq:Number; private var log:String; //constructor: public function Check(frequency:Number, url:String, theOp:String) { trace("url set:"+url); trace("operation set:"+theOp); this.WSDLURL(url); this.operation = theOp; this.suppressInvalidCalls = true; checkFreq = frequency; } // methods: function sendLog():String { trace("sendLog called"); this.trigger(); return log; }
View Replies !
View Related
Creating A Class To Extend Math
i have a function that i wrote in flash mx, and now that i'm using flash mx 2004, i'm going to have to use a class.
the function is like this:
ActionScript Code:
//as 1.0:function formatNumber(numberToFormat, decimalPlaces) {//}
how would i format that to put it into a class that extends the Math setion of as 2.0?
View Replies !
View Related
Inherit / Extend Class Calls Constructor...
Hi,
Class A extends class B like so:
public class A extends B{}
Why is class B's constructor called? I thought when A extends B, A gets all of B's methods and variables, great; but I don't need the constructor called because class B has already been created. I just want class A to inherit all of B's methods and variables. Can a class have two constructors, so when I extend class B an empty constructor is called but when I instantiate it the constructor with code is called?
I feel like I’m missing something here.
Thanks,
4dplane
View Replies !
View Related
Inherit / Extend Class Calls Constructor...
Hi,
Class A extends class B like so:
public class A extends B{}
Why is class B's constructor called? I thought when A extends B, A gets all of B's methods and variables, great; but I don't need the constructor called because class B has already been created. I just want class A to inherit all of B's methods and variables. Can a class have two constructors, so when I extend class B an empty constructor is called but when I instantiate it the constructor with code is called?
I feel like I’m missing something here.
Thanks,
4dplane
View Replies !
View Related
Logic Behind Flash's Classes (or: When/where To Extend A Class)
Hey there,
I'm still quite new to flash &programming and I'm half way through a book called "object-oriented actionscript for flash 8".
I am reading about the framework of classes that flash provides and I'm just wondering how exactly "borders" are decided between classed and extensions for them
for example: the movie class and the UIObject class (UIObject extends Movie class):
in Movie class there is a function called moveTo(x:Number,y:Number)
then in UIObject there is a functin called move(x:Number,y:Number)
so why aren't both in Movie or both in UIObject? are they really the same thing, but it just depends where you want to access movement from? I'm generally confused in when I extend classes, and where I would "draw the line" between one class and the extension of it, and Im trying to get an idea of logic by looking at how flash does it.
Any comments or pointers are much appreciated!Thanks!
View Replies !
View Related
[AS2.0]extend Class, No Error, Doesn't Work
Hi, to find an error in ths one is pretty challenging, I have a class which I wanted to make this "menu" moveclip thing extends when I roll Over and go back to the original length if roll out, here's the code, it returns no errors, just doesn't work...
thanks for your help, the code is pretty long but please, if you have time, I really need your help...
ActionScript Code:
//ClASS CODE
class ExtendBar extends MovieClip{
var homeX:Number;
var finalX:Number;
var myClip:MovieClip;
var extendSpeed:Number;
var slowDown:Number
var extend:Boolean;
function ExtendBar(origX:Number, endX:Number, clips:MovieClip, slow:Number){
homeX = origX;
finalX = endX;
myClip = clips;
slowDown = slow;
}
function extendIt(){
myClip.onEnterFrame = function(){
this.extend = true;
extendSpeed = Math.round((finalX - homeX)*slowDown);
if(extendSpeed == 0){
this.extend = false;
this._xscale = finalX;
delete this.onEnterFrame;
}
myClip._xscale += extendSpeed;
}
}
}
ActionScript Code:
//FLA CODE
var menu:ExtendBar = new ExtendBar(20, 400, this, .05);
menu.onRollOver = function(){
extendIt();
}
View Replies !
View Related
Tween Color Class Not The Color I Expected
Here is the code for a gallery slide show I'm working on.
What I'm wanting is the background to change color with each gallery. To tween over a few seconds. I have not included the gallery images. Sorry
I don't understand why the colors are so different from the what the hexadecimal colors I intended.
B2C3D0
598479
D16546
You have to go to the gallery button to see what I'm getting at.
Thanks for your help
kiwiupover
http://www.missionadventures.co.nz/k...er/gallery.fla
babyPic.onRelease = function() {
_parent._parent._parent.gotoAndPlay("galleryBaby") ;
var colour:Color = new Color(_parent._parent._parent.galleryBack);
colour.getRGB(_parent._parent._parent.galleryBack) ;
var trans:Object = colour.getTransform();
var rb:Tween = new Tween(trans, "rb", Strong.easeOut, trans.rb, 0xB2, 3, true);
var gb:Tween = new Tween(trans, "gb", Strong.easeOut, trans.gb, 0xC3, 3, true);
var bb:Tween = new Tween(trans, "bb", Strong.easeOut, trans.bb, 0xD0, 3, true);
rb.onMotionChanged = function():Void {
colour.setTransform(trans)
};
};
View Replies !
View Related
Extend Class Movieclip And Movieclip Off Stage
Hi all,
Using Flash 8 and getting over to AS2.0 I got this problem. Could not find any answer on the forum until now.
I am trying to get some more grips on AS2.0 and do this by making a small game. On several frames are movieclips: mc1 mc2 etc. When the user clicks on them, the total number of clicks is recorded (among others) for each movieclip. On different frames are different movieclips.
I tried three ways.
1. First I defined a class MyMovieClipClass extends MovieClip with:
code:
private var clicks: Number
private function onPress: Void {
clicks++;
// do other things
}
public function howMuch: Number{ // return clicks }
Movieclips mc1, mc2, etc are defined being a member of this class in ‘linkage’.
The problem arose that when on a frame without mc1 I could not access mc1.howMuch() becase in that frame there is no mc1.
2. Then I defined two classes MyMovieClipClassA and MyMovieClipClassB
The movieclip on stage mc1 is a member of Class A and var clicks is in Class B.
The instance name of class B is derivated from the instance name on stage:
mc1 (ClassA) is kindof connected with mc1_obj (ClassB)
MyMovieClipClassA extends MovieClip with:
code:
private function onPress: Void {
// make instName = this._name + “obj”;
instName.clicks++;
// do other things
}
MyMovieClipClassB with:
code:
private var clicks: Number
public function howMuch: Number{ // return clicks }
In the timeline I then define:
code:
var item1: MyMovieClipClassA = new MyMovieClipClassA();
var item1_obj: MyMovieClipClassB = new MyMovieClipClassB();
which is not very elegant.
(the movieclip to which this belongs has the name item1)
3. I tried to declare ‘_name + “_obj”’ in de constructor of ClassA but did not succeed.
Anybody any suggestions for an elegant solution in which different movieclips in different frames on stage can be tracked using classes?
Thanks in advance for your reaction.
View Replies !
View Related
Making Color Transparent
I just bought MX. I was used to working in 4.0.
Now I can't find the simple mixer that allowed me to make a color transparent without having to turn it into an instance.
It used to be so simple.
Humbly submitted this 5th day of November 2002.
Igottalugh
View Replies !
View Related
Making Color Change Clickable
This is a visual aid of what I am trying to accomplish:
I am trying to code the colored square buttons so that when clicked, the attached movie clips on stage and inside "hcArray" will change to the same color as the square button that has been clicked.
I have set up 2 arrays, one containing the instance names of the color buttons and the other containing the color hex values:
PHP Code:
var hairColor:Array = new Array();
hairColor = [hairSwatch_Black, hairSwatch_Red, hairSwatch_Blue, hairSwatch_Purple, hairSwatch_Green, hairSwatch_Magnta];
var hairRGB_Num:Array = new Array();
hairRGB_Num = [0x000000, 0xFF0033, 0x000099, 0x660099, 0x034D1B, 0xC301C0];
Next I set up my function but I can't get it to work:
PHP Code:
function changeHairColor() {
if (hcArray.length>0) {// Function will only work if there are movie clip instances inside hcArray.
for (var i = 0; i<hairColor.length; i++) {
if (_root.hairColor[i].hitTest(_xmouse, _ymouse, true)) {// If any of the colored buttons detects the mouse over it...
hairColor[i].onRelease = function() { // Change the color of the instances inside hcArray when the mouse is released.
for (var j = 0; j<hcArray.length; j++) {
hcColor = new Color(hcArray[j]);
hcColor.setRGB(hairRGB_Num[i]);
}
};
}
}
}
}
I made the discovery that if I comment out the "onRelease" code as so...
PHP Code:
function changeHairColor() {
if (hcArray.length>0) {
for (var i = 0; i<hairColor.length; i++) {
if (_root.hairColor[i].hitTest(_root._xmouse, _root._ymouse, true)) {
for (var j = 0; j<hcArray.length; j++) {
//hairColor[i].onRelease = function() {
hcColor = new Color(hcArray[j]);
hcColor.setRGB(hairRGB_Num[i]);
//};
}
}
}
}
}
...the color change works when you pass the mouse over the color squares but they are no longer clickable.
Any idea on how to fix this? the .fla file is here.
Thanks,
View Replies !
View Related
Making A 'fill With Color' Application
Hi.
I'm totally new with Flash, and I'm making an application where the user can fill some drawings with color. This is going to be a 'game' for kids aged 5-10, so it have to be really simple to use. You know, pick a color and fill a part of the drawing. The drawings are premade templates.
Since I haven't really learned enough about Flash to know if there is an easy way to do this, I'm asking you guys...
Any suggestion would be appreciated!
Rune Heggemsli,
HMP
View Replies !
View Related
Color Class
I have a set of buttons lined up together. I want to create an effect where the mouse goes on one button..the rest others should fade. i tried use color class that dynamically does this.. but to no help..
I have made movie symbol wid buttons inside them (for each individual button) place them side by side on the stage. given each of them instance names.
I wrote the following action script in the first frame
rgbcontact= new Color(contact) where contact is an instance name
(tried relative and absolute path also)
and on the movie on(rollover){
rgbcontact.setRGB(dummycolor in hex)
}
doesnt seem to help..really appreciate any help
thanks
View Replies !
View Related
AS 3.0 Color Class?
ActionScript Code:
var line_color:Color = lineColor(type);
public function lineColor(type:String):Color
{
var col:Color = new Color();
switch(type)
{
case "spouse":
col = 0xcccccc;
break;
default :
col = 0xFE7C1A;
}
return col;
};
I get an error because I do not know where to import the color class from.
1046: Type was not found or was not a compile-time constant: Color.
The only thing I can find in the help about a color class is import fl.motion.Color;
Can someone show the way Thanks
View Replies !
View Related
Color Class
Is there a better way of writing this? Maybe move the last two lines up and have loop refer to the var. I am not sure how to accomplish this. What I am trying to do is change any movie clip with an instance name beginning in L.
Attach Code
for ( j=0; j<3; j++ ){
al = eval("L" +j);
var bl:Color = new Color(al);
bl.setRGB(0xFF0000);//red
};
View Replies !
View Related
Class Color Set
Hey guys,
I have created a class called RButton which extends MovieClip.
I want it so that when i use attachMovie("RButton"...) to create an instance of this i can send it a hex color value and it will be created in that color. How would i go about doing this?
Cheers!
View Replies !
View Related
Making A Particular Color In The Loaded Movie Transparent
i have a movieclip in which a bird is flying in a white rectangular background. when i load it in to my main swf, the background color is opaque -- (bird is flying along with its white rectangle). it's not becoming transparent as expected.
The external clip was created from an avi file using some frame extraction tool; so i don't have access to its background color settings. i think its drawing a white layer as background
is there a way by which i can make one particular color (here its white) of a loaded movieclip transparent?
i guess i can't use color transforms as its not an image. can i access it frame by frame and make one particular color transparent in all frames? is that possible or am i too ambitious?
View Replies !
View Related
Scrubber: Making Content Behind The Playhead Different Color
Hi,
I, like many of you am using Lee's loader/scrubber tutorial for my own project and have noticed that some of you have modified your own projects to make the loadbar content behind the playhead a different color. i.e. the FLV loads, buffers, then starts with the playhead following the current playing frame of the FLV, and any loadbar content behind the playhead is a different color.. How is this effect achieved?
Do u use another movieclip over the top of the loadbar that's _width is equal to the distance between the x of the load bar and the x the playhead?
View Replies !
View Related
Text Color In Class
Code:
private function meselection() {
this["indicator"].gotoAndPlay("onselect")
var mytween:Tween = new Tween(this["zemin_mc"] ,"_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, 3, true);
var my_fmt:TextFormat
my_fmt.color = #FFFFFF
this["btn_caption"].setTextFormat(my_fmt);
}
why this script gives error "Operator '=' must be followed by an operand"
i tryed also same in other fla (not in class) its worked well, but how can i use this method in a class?
View Replies !
View Related
Color Picker Class
Needed a little color picker for a project and wanted entirely scripted, so came up with this (the color picker class needs the Grid class, so I'll put both here):
OBO_ColorPicker.as:
ActionScript Code:
import com.onebyonedesign.utils.Grid;import flash.filters.DropShadowFilter;import flash.display.BitmapData;import flash.geom.ColorTransform;import flash.geom.Transform;class com.onebyonedesign.utils.OBO_ColorPicker { private var _displayWidth:Number; private var _displayHeight:Number; private var _currentColor:Number; private var _displaySwatch:MovieClip; private var _swatches:MovieClip; private var __parent:MovieClip; private var _swatchBmp:BitmapData; private var _cxf:ColorTransform; private var _xf:Transform; public var onColorSelected:Function; public var onColorHover:Function; /** * @author Devon O. Wolfgang * @date 3/2/2007 5:46 PM * @description Creates a "color picker" for user to choose a custom color from a palette of 216 web safe choices. * Broadcasts onColorHover() event when mouse is moved over swatch palette. * Broadcasts onColorSelected() event when a color is selected. * Requires class com.onebyonedesign.utils.Grid. * * * @param w Number: width of color display * @param h Number: height of color display * @param defaultColor Number: default color color picker * @param parent MovieClip: the parent of the color picker (could be _root of .swf, but an empty MovieClip is recommended). * * * @usage import com.onebyonedesign.utils.OBO_ColorPicker; var cp_mc:MovieClip = this.createEmptyMovieClip("cp", this.getNextHighestDepth()); cp_mc._x = 200; cp_mc._y = 200; var my_cp:OBO_ColorPicker = new OBO_ColorPicker(30, 30, 0x000000, cp_mc); my_cp.onColorSelected = function(col:Number) { trace(col); }; */ // Public function OBO_ColorPicker(w:Number, h:Number, defaultColor:Number, parent:MovieClip) { _displayWidth = w; _displayHeight = h; __parent = parent; _currentColor = defaultColor; init(); } public function set enabled(bool:Boolean):Void { _displaySwatch.enabled = bool; } public function get color():Number { return _currentColor; } public function get colorString():String { var col:String = _currentColor.toString(16); var colArray:Array = col.split(""); var len:Number = colArray.length; if (len < 6) { for (var i = len; i < 6; i++) { colArray.unshift("0"); } } return colArray.join("").toUpperCase(); } // private private function init():Void { createDisplaySwatch(); createSwatches(); initDisplaySwatch(); } private function createDisplaySwatch():Void { _displaySwatch = createMovieClip(_displayWidth, _displayHeight, _currentColor, __parent); _xf = new Transform(_displaySwatch); _cxf = new ColorTransform(); } private function createSwatches():Void { _swatches = __parent.createEmptyMovieClip("s", __parent.getNextHighestDepth()); var swatchWidth:Number = 10; var swatchHeight:Number = 6; var colorArray:Array = makeColorArray(); var grid:Grid = new Grid(12, 18, swatchHeight, swatchWidth, 0, 0); var len:Number = grid.length; for (var i = 0; i < len; i++) { var swatch:MovieClip = createMovieClip(swatchWidth, swatchHeight, colorArray[i], _swatches); swatch._x = grid[i].x; swatch._y = grid[i].y; } initSwatches(); } private function initDisplaySwatch():Void { var cp:OBO_ColorPicker = this; _displaySwatch.onRelease = function() { cp.showSwatches(); this.enabled = false; } } private function createMovieClip(w:Number, h:Number, c:Number, par:MovieClip):MovieClip { var mc:MovieClip = par.createEmptyMovieClip("s" + par.getNextHighestDepth(), par.getNextHighestDepth()); with (mc) { beginFill(c); moveTo(0, 0); lineTo(w, 0); lineTo(w, h); lineTo(0, h); endFill(); } return mc; } private function makeColorArray():Array { var hArray:Array = new Array("00", "33", "66", "99", "CC", "FF"); var cArray:Array = new Array(); var len:Number = hArray.length; for (var r = 0; r < len; r++) { for (var g = 0; g < len; g++) { for (var b = 0; b < len; b++) { cArray.push(Number("0x" + hArray[r] + hArray[g] + hArray[b])); } } } return cArray; } private function initSwatches():Void { var cp:OBO_ColorPicker = this; _swatchBmp = new BitmapData(_swatches._width, _swatches._height); _swatchBmp.draw(_swatches); _swatches.filters = [new DropShadowFilter(4, 90, 0x000000, .6, 5, 5, 1, 3)]; _swatches.useHandCursor = false; _swatches.onRollOver = function(){ this.onMouseMove = function() { cp._cxf.rgb = cp._swatchBmp.getPixel(this._xmouse, this._ymouse); cp._xf.colorTransform = cp._cxf; cp.onColorHover(cp._cxf.rgb); } } _swatches.onRollOut = _swatches.onDragOut = function() { delete this.onMouseMove; } _swatches.onRelease = function() { cp._currentColor = cp._swatchBmp.getPixel(this._xmouse, this._ymouse); this._visible = false; cp.onColorSelected(cp._currentColor); cp._displaySwatch.enabled = true; } _swatches._visible = false; } private function showSwatches() { // position swatches _swatches._x = _displayWidth + 5; _swatches._y = -(_swatches._height) + _displayHeight; var pt:Object = {x:_swatches._x, y:_swatches._y}; __parent.localToGlobal(pt); if (pt.y < 0) _swatches._y = 0; if (pt.x + _swatches._width > Stage.width) _swatches._x = -(_swatches._width) - 5; _swatches._visible = true; }}
Grid.as
ActionScript Code:
/*** Grid class* @author: Devon O.* @date: 15JAN06*/class com.onebyonedesign.utils.Grid extends Array { private var _cols:Number; private var _rows:Number; /** * Grid returns an array of objects with x and y coordinates (properties) based on the number of columns, * rows, height and width of cells, and the x and y value of the upper left corner. * * @usage myGrid=new Grid (columns, rows, cellHeight, cellWidth, topLeftCornerX, topLeftCornerY) * @param cols: The number of columns * @param rows: The number of rows * @param cellHeight: The height of the grid cell * @param cellWidth: The width of the grid cell * @param x: The x position of the top left corner of the grid * @param y: The y position of the top left corner of the grid * @return Grid (an array of objects each containing two properties: x and y) */ public function Grid (cols : Number, rows : Number, cellHeight : Number, cellWidth : Number, x : Number, y : Number) { _cols = cols; _rows = rows; var numCells : Number = cols * rows; var curx : Number = x; for (var i = 0; i < numCells; i ++) { this [i] = new Object ({x : curx, y : y}); curx += cellWidth; if ( ! ((i + 1) % cols)) { curx = x; y += cellHeight; } } } // /** * The shuffle method will return the array of grid coordinates in a random order. * * @usage myGrid.shuffle() * @return Void */ public function shuffle () : Void { var len : Number = this.length; var temp : Object = new Object (); for (var i = 0; i < len; i ++) { var rand : Number = Math.floor (Math.random () * len); temp = this [i]; this [i] = this [rand]; this [rand] = temp; } } // Getters public function get columns():Number { return _cols; } public function get rows():Number { return _rows; }}
A quickie example: http://www.onebyonedesign.com/flash/colorPicker
View Replies !
View Related
[AS3] Color Parser Class
A class with a static method that parses a good amount of the current W3C methods for representing colors, including: #RGB; #RRGGBB; rgb(r, g, b); rgb(r%, g%, b%); and the SVG color names (the list is here).
The file is a .txt (since .as aren't allowed). Just rename the extension and the class will be ready for use.
View Replies !
View Related
Tween Class For Color
Could anyone point me in the direction of a class for Tweening color?
I've been working on my own but failed, tried downloading one but didn't work... so if anyone could help I would really appreciate it.
Cheers
Gorka
View Replies !
View Related
Making Object Turn Color As It Goes Over Item In Layer Behind It
I'm quite new to the Flash environment, so there might be an easy answer to this question. I have a white vector object moving over a black background. It moves across the screen this way until it goes over a small white box on a layer. Is there a way to make the moving object turn black as it enters the white area? In other words, so the highest contrast is maintained dependent on what color is behind it?
Your help would be greatly appreciated. If you want to see what I'm talking about e-mail me (vervelde@dordt.edu) and I can send you an flv file.
Frustrated in Iowa
View Replies !
View Related
Making This A Class?
The script below is used to generate animated "strings" or lines that attach to a cloud (which is nested in the "main" MovieClip on my stage). Since the cloud is just a MovieClip on my stage I can't make multiple instances of that cloud (along with the connecting strings). I was told that a good way to achieve this would be to make a custom class, but I have no clue how to do this, can someone help me?
PHP Code:
var frontString:Shape = new Shape();
var backString:Shape = new Shape();
var frontWind:Number = 100;
var backWind:Number = 75;
var frontGust:Number;
var backGust:Number;
main.cloud.x = stage.stageWidth / 2;
main.cloud.y = (stage.stageHeight / 2) / 3;
goWest();
function goWest():void{
frontGust = 100 + Math.ceil(Math.random() * 40);
backGust = 75 + Math.ceil(Math.random() * 40);
stage.addEventListener(Event.ENTER_FRAME, westWinder);
}
function goEast():void{
stage.removeEventListener(Event.ENTER_FRAME, westWinder);
frontGust = 100 + Math.ceil(Math.random() * -40);
backGust = 75 + Math.ceil(Math.random() * -40);
stage.addEventListener(Event.ENTER_FRAME, eastWinder);
}
function westWinder(Event):void{
if(frontWind < frontGust){
frontWind++;
backWind--;
main.cloud.x++;
}else{
goEast();
}
}
function eastWinder(Event):void{
if(frontWind > frontGust){
frontWind--;
backWind++;
main.cloud.x--;
}else{
goWest();
}
}
stage.addEventListener(Event.ENTER_FRAME, drawString);
function drawString(Event){
frontString.graphics.clear();
frontString.graphics.lineStyle(2);
frontString.graphics.moveTo(main.cloud.x - 100, main.cloud.y);
frontString.graphics.curveTo(main.cloud.x - frontWind, main.cloud.y, stage.stageWidth/2 - 100, -300);
backString.graphics.clear();
backString.graphics.lineStyle(2);
backString.graphics.moveTo(main.cloud.x + 75, main.cloud.y);
backString.graphics.curveTo(main.cloud.x + backWind, main.cloud.y, stage.stageWidth/2 + 75, -300);
}
addChild(frontString);
addChild(backString);
addChild(main.cloud);
View Replies !
View Related
[F8] MC Color Change Using The Tween Class?
Hi, i am wanting to change the colour of a movie clip gradually on the click of a button. I found a good script but it runs continually when you are not actually changing the clip colour placing a noticable strain on the processor.
After a bit of digging i have seen a few mentions of tweening the colour using the tween class but they all seem rather complicated.
Can anyone help me out with the tween class way of doing this?
Cheers
Neil
View Replies !
View Related
Changing Color Of MovieClip From Class?
I have a class that sends clouds movieclips across the sky.
I have it so the current time is set, to your computers time. I'm using cases, and within my main timeline have it so the background changes colors, depending on the time.
I was wondering how would I go about changing the color of the movieclip, which is from a class.
- Do i change the color within the class(if so how do I call a variable(myTime) from my main timeline to my class(because certain time will make the MC a certain color)? or can I even do cases in classes?
-Or do I change all the cloud colors from my main timeLine. I have 3 functions calling the cloud class 3 different times, resulting in 3 different clouds.
sorry I'm pretty lost, when it comes to classes and maintime line. except for the basics
View Replies !
View Related
Dynamic Color Tween Class
Hey everyone!
Thanks so much for the help I got last night and today. Here is what I came up with for dynamic color tweens with your guidance.
Cheers.
class Transitions.as
ActionScript Code:
// --> don't copy this comments it will screw up formating <<--
// because of some bug with the as parse here at AS[org]
/**
* Class for dynamic transitions
*
* @author Flash Gordon
* @version 1.0.0
*
*/
import mx.transitions.Tween;
import mx.transitions.easing.*;
import flash.geom.Point;
import flash.display.BitmapData;
import flash.geom.ColorTransform;
import flash.geom.Transform;
class Transitions {
// properties used throughout class
private var target:MovieClip; // the movieclip that will recieve the transitions
private var time:Number; // specifies the time of the transitions
// properties used for color tween
private var dynamicColor:Number;
/**
* CONSTRUCTOR
*
* @ param target Specifies the MovieClip with will recieve the transitions
* @ param time OPTIONAL Specifies the time length of the tween in seconds
*/
public function Transitions(target:MovieClip, time:Number)
{
this.target = target;
if (time == undefined) this.time = 0.8;
else this.time = time;
}
/**
* method to tween the color of a **solid** color movieclip
*
* @ param toColor is a hexidecimal number that the target tweens to
* @ param beginColor (OPTIONAL) is a hexidecimal number that is the beginning color of the tween.
* If left blank, the class attemps to find the color automatically
* @ param point OPTIONAL Is a point where the target has color
*/
public function colorTween(toColor:Number, beginColor:Number, point:Point):Void
{
// check params for valid values
if (toColor == undefined) throw new Error("Must define an end color");
if (point == undefined) point = new Point( Math.round(target._width/2), Math.round(target._height/2) );
// if the begining color is not specified find it dynamically
if (beginColor == undefined && dynamicColor == undefined) {
var bmp:BitmapData = new BitmapData(target._width, target._height);
bmp.draw(target);
beginColor = bmp.getPixel(point.x, point.y);
trace("beginning color is 0x" + beginColor.toString(16));
}
// if instance of class was used once, the dynamic color is stored in a property
else if (dynamicColor != undefined) beginColor = dynamicColor;
// set up to transform the color
var color:ColorTransform = new ColorTransform();
var trans:Transform = new Transform(target);
// get the individual (RGB) color values
var holder:Object = new Object();
holder.red = beginColor >>> (4*4) & 0xFF;
holder.green = beginColor >>> (2*4) & 0xFF;
holder.blue = beginColor >>> (0*4) & 0xFF;
var toRed:Number = toColor >>> (4*4) & 0xFF;
var toGreen:Number = toColor >>> (2*4) & 0xFF;
var toBlue:Number = toColor >>> (0*4) & 0xFF;
// tween the color
var redTween:Tween = new Tween(holder, "red", None.easeNone, holder.red, toRed, time, true);
var greenTween:Tween = new Tween(holder, "green", None.easeNone, holder.green, toGreen, time, true);
var blueTween:Tween = new Tween(holder, "blue", None.easeNone, holder.blue, toBlue, time, true);
blueTween.onMotionChanged = mx.utils.Delegate.create(this, onMotionChanged);
function onMotionChanged():Void
{
color.rgb = dynamicColor = ( holder.red << (4 * 4) ) | ( holder.green << (2* 4) ) | ( holder.blue << (0 * 4) );
trans.colorTransform = color;
}
blueTween.onMotionFinished = Delegate.create(this, onMotionFinished);
function onMotionFinished():Void
{
trace( "color is now 0x" + dynamicColor.toString(16) );
trace( "" );
}
}
}
in fla
ActionScript Code:
// don't copy this line
// make a movieclip named ball
// then click the mouse
var myTran:Transitions = new Transitions(ball);
onMouseDown = function() {
var tweenTo:Number = Math.random() * 0xFFFFFF;
myTran.colorTween(tweenTo);
}
attached is the swf.
cheers and thanks everyone!
View Replies !
View Related
|