;

PDA

Click to See Complete Forum and Search --> : [RESOLVED] Problems Using Classes


xhanubis
08-24-2006, 06:49 AM
I have come across a cool class I would like to use but have run into some problems using it. Could some please help me.

The example of the class in action is here:

http://pixelfumes.blogspot.com/2006/07/business-card-flip-effect-class-with.html

I created my .as file and name it flip.as and place it in the same folder as my movie.

this is the content of my flip.as file:

import flash.filters.BlurFilter;

import flash.filters.DropShadowFilter;

import mx.transitions.Tween;

import mx.transitions.easing.*;



class CardFlip{

private var cardWrapper:MovieClip;

private var cardFront:MovieClip;

private var cardBack:MovieClip;

private var cardBackLinkageID:String;

private var cardSide:Number = 1;

private var flipComplete:Boolean = false;

private var xAxis:Number;

private var dropShadow:DropShadowFilter = null;



function CardFlip(cardW:MovieClip,back:String,xa:Number,ds: DropShadowFilter){

cardWrapper = cardW;



cardBackLinkageID = back;

//init card

cardWrapper.createEmptyMovieClip("back",cardWrapper.getNextHighestDepth());

cardBack = cardWrapper.back;

cardBack._visible = false;

cardBack.attachMovie(cardBackLinkageID,"mc",1);

xAxis = xa;

if(ds){

dropShadow = ds;

cardWrapper.filters = [ds];

}

}



public function flip(t,b,r1,r2){

flipComplete = false;

var time:Number = t;

var blurAmt:Number = b;



switch(cardSide){

case 1:

cardSide = 2;

var cfrTween = new Tween(cardWrapper, "_rotation", Strong.easeIn, cardWrapper._rotation, r2, time, true);

break;

case 2:

cardSide = 1;

var cfrTween = new Tween(cardWrapper, "_rotation", Strong.easeIn, cardWrapper._rotation, r1, time, true);

break;

}



var myBlur:BlurFilter = new BlurFilter(0, 0, 3);







cardWrapper.filters = [myBlur,dropShadow];



var blurTween = new Tween(myBlur, "blurX", Strong.easeIn, blurAmt, blurAmt, time, true);

blurTween.cRef = this;

blurTween.onMotionChanged = function() {

this.cRef.cardWrapper.filters = [myBlur,this.cRef.dropShadow];

}



var cfTween = new Tween(cardWrapper, "_xscale", Strong.easeIn, 100, 0, time, true);

var cfxTween = new Tween(cardWrapper, "_x", Strong.easeIn, xAxis, xAxis + cardWrapper._width/2, time, true);



cfTween.cRef = this;

cfTween.onMotionFinished = function(){

if(this.cRef.cardSide == 1){

this.cRef.cardBack._alpha = 0;

this.cRef.cardBack._visible = false;

}else{

this.cRef.cardBack._visible = true;

this.cRef.cardBack._alpha = 100;

}

if(flipComplete != true){

cfTween.yoyo();

cfxTween.yoyo();

flipComplete = true;

}else{

this.cRef.cardWrapper.filters = [new BlurFilter(0, 0, 3),this.cRef.dropShadow];

}

}

}

}

on the first frame of my movie I have:

import flip.as;

And on my button I have:

on (release) {
cf = new CardFlip(card_mc, "cardBack_mc", 50, ds);
}

The mc onstage is named:

card_mc and the one in the library has the identifier:

cardBack_mc:

When I press my button nothing happens, what am I doing wrong?

Thanks

cancerinform
08-24-2006, 09:48 AM
First of all give your button a name and then put this script on the main timeline and of course eliminate your former buttonscript.

import flip;
myButton.onPress=function()
{
var cf:flip = new flip(card_mc, "cardBack_mc", 50, ds);
}

Then in the .as file change the class name
class flip {

and change the constructor, which is the function name with parameters
function flip (cardW:MovieClip,back:String,xa:Number,ds:DropShad owFilter){


The class name, the file name and the constructor name have to be the same.

xhanubis
08-24-2006, 03:40 PM
Thanks much for the help!

Unfortunately it has not worked for me. this is the code I have now.

on the timeline:

import flip.as;
myButton.onPress = function() {
var flip = new flip(card_mc, "cardBack_mc", 50, ds);
};

when I use the code:

import flip.as;
myButton.onPress = function() {
var cf:flip = new flip(card_mc, "cardBack_mc", 50, ds);
};

I get an error.

in my class I have:


import flash.filters.BlurFilter;

import flash.filters.DropShadowFilter;

import mx.transitions.Tween;

import mx.transitions.easing.*;



class flip{

private var cardWrapper:MovieClip;

private var cardFront:MovieClip;

private var cardBack:MovieClip;

private var cardBackLinkageID:String;

private var cardSide:Number = 1;

private var flipComplete:Boolean = false;

private var xAxis:Number;

private var dropShadow:DropShadowFilter = null;



function CardFlip(cardW:MovieClip,back:String,xa:Number,ds: DropShadowFilter){

cardWrapper = cardW;



cardBackLinkageID = back;

//init card

cardWrapper.createEmptyMovieClip("back",cardWrapper.getNextHighestDepth());

cardBack = cardWrapper.back;

cardBack._visible = false;

cardBack.attachMovie(cardBackLinkageID,"mc",1);

xAxis = xa;

if(ds){

dropShadow = ds;

cardWrapper.filters = [ds];

}

}



public function flip(t,b,r1,r2){

flipComplete = false;

var time:Number = t;

var blurAmt:Number = b;



switch(cardSide){

case 1:

cardSide = 2;

var cfrTween = new Tween(cardWrapper, "_rotation", Strong.easeIn, cardWrapper._rotation, r2, time, true);

break;

case 2:

cardSide = 1;

var cfrTween = new Tween(cardWrapper, "_rotation", Strong.easeIn, cardWrapper._rotation, r1, time, true);

break;

}



var myBlur:BlurFilter = new BlurFilter(0, 0, 3);







cardWrapper.filters = [myBlur,dropShadow];



var blurTween = new Tween(myBlur, "blurX", Strong.easeIn, blurAmt, blurAmt, time, true);

blurTween.cRef = this;

blurTween.onMotionChanged = function() {

this.cRef.cardWrapper.filters = [myBlur,this.cRef.dropShadow];

}



var cfTween = new Tween(cardWrapper, "_xscale", Strong.easeIn, 100, 0, time, true);

var cfxTween = new Tween(cardWrapper, "_x", Strong.easeIn, xAxis, xAxis + cardWrapper._width/2, time, true);



cfTween.cRef = this;

cfTween.onMotionFinished = function(){

if(this.cRef.cardSide == 1){

this.cRef.cardBack._alpha = 0;

this.cRef.cardBack._visible = false;

}else{

this.cRef.cardBack._visible = true;

this.cRef.cardBack._alpha = 100;

}

if(flipComplete != true){

cfTween.yoyo();

cfxTween.yoyo();

flipComplete = true;

}else{

this.cRef.cardWrapper.filters = [new BlurFilter(0, 0, 3),this.cRef.dropShadow];

}

}

}

}

Thanks

cancerinform
08-24-2006, 03:45 PM
import flip;

xhanubis
08-24-2006, 07:36 PM
Hi Again I must be doing something wrong. I have everything you way you instructed. And I get no errors now. but still nothing happens. Any other ideas?

xhanubis
08-24-2006, 10:50 PM
I have uploaded the files so you can take a look at the actual work.

http://www.jermainevalentine.com/demo/card.zip

Thanks

cancerinform
08-25-2006, 06:55 AM
1. Since this is a tutorial have you followed the instructions?
2. Although that is up to you, but usually people don't change the names of classes developed by others unless they make intensive changes. That brought you into trouble in the first hand.;)

xhanubis
08-25-2006, 07:07 AM
well I think I followed your instructions. Have you managed to make it work? please let me know so at least I know that it is possible using the info I have.

Thanks :)

cancerinform
08-25-2006, 07:37 AM
You have to get it work. if I have to create everybody's movies I will be sitting here 24hours/day. :)

I am only trying to eliminate the problems you are encountering, which I see when I see that script.

This is not my tutorial. The first thing I do when I read a tutorial is not change anything but exactly follow the instructions.

cancerinform
08-25-2006, 10:34 AM
I had not seen your example, since I did not get all the emails. The guy who created this script has left out important information, may be deliberately :mad: . From his instructions the script will not work. Your version had additional problems.
1. You renamed the file to flip, but you did not rename the constructor (function CardFlip). Then it won't work. If you rename it to flip you get into trouble because there is a function called flip and you can only have one constructor.

2. The function flip in the script is public. It means that most probably you need to add this function in your fla somewhere. However, now the problem starts. The parameters are all numbers. I added some and get some effect, but not what I want.

I don't understand the whole script just by looking at it. I don't even know he posted the right script. From the comments you can see that others have problems, too. I will have a look may be tonight, but I can't promise. :)

I have attached the modified version I have so far.

cancerinform
08-25-2006, 11:10 AM
Ok, place the image at position x 200 and then use this script in your fla: :)

import CardFlip;
myButton.onPress = function ()
{
var myFlip = new CardFlip (card_mc, "cardBack_mc", 200, ds);
myFlip.flip (1, 20, 0, 360);
};


You can change the way the card flips with some scroller as shown on that original site.

xhanubis
08-25-2006, 07:34 PM
Thanks!!!

You rock Will play around with it and see what I can come up with!!