A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: [RESOLVED] Problems Using Classes

  1. #1
    JayVEE
    Join Date
    Jan 2001
    Location
    Kgn Jamaica
    Posts
    44

    [RESOLVED] Problems Using Classes

    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/...lass-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:

    Code:
    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:

    Code:
    import flip.as;
    And on my button I have:

    Code:
    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
    'til next time

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    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,dsropShadowFilter){


    The class name, the file name and the constructor name have to be the same.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    JayVEE
    Join Date
    Jan 2001
    Location
    Kgn Jamaica
    Posts
    44

    Still no luck!

    Thanks much for the help!

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

    on the timeline:

    Code:
    import flip.as;
    myButton.onPress = function() {
    	var flip = new flip(card_mc, "cardBack_mc", 50, ds);
    };
    when I use the code:

    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:


    Code:
    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
    'til next time

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    import flip;
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    JayVEE
    Join Date
    Jan 2001
    Location
    Kgn Jamaica
    Posts
    44
    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?
    'til next time

  6. #6
    JayVEE
    Join Date
    Jan 2001
    Location
    Kgn Jamaica
    Posts
    44

    The Files

    I have uploaded the files so you can take a look at the actual work.

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

    Thanks
    'til next time

  7. #7
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    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.
    - The right of the People to create Flash movies shall not be infringed. -

  8. #8
    JayVEE
    Join Date
    Jan 2001
    Location
    Kgn Jamaica
    Posts
    44
    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
    'til next time

  9. #9
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    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.
    - The right of the People to create Flash movies shall not be infringed. -

  10. #10
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    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 . 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.
    Attached Files Attached Files
    Last edited by cancerinform; 08-25-2006 at 11:38 AM.
    - The right of the People to create Flash movies shall not be infringed. -

  11. #11
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    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.
    Last edited by cancerinform; 08-25-2006 at 11:31 AM.
    - The right of the People to create Flash movies shall not be infringed. -

  12. #12
    JayVEE
    Join Date
    Jan 2001
    Location
    Kgn Jamaica
    Posts
    44
    Thanks!!!

    You rock Will play around with it and see what I can come up with!!
    'til next time

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center