Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

Problem with rotating MovieClip created at runtime

This is a discussion on Problem with rotating MovieClip created at runtime within the advanced Actionscript 3.0 forums, part of the Flash CS3 eng category; Hi all, my first post here, I hope you'll be able to help me with my problem. I'm ...


Go Back   Forum Flash CS3 Flash CS4 > English Forums > Flash CS3 eng > advanced Actionscript 3.0

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-04-08, 15:49
Junior Member
 
Join Date: Mar 2008
Posts: 6
Rep Power: 0
ibreslau is on a distinguished road
Problem with rotating MovieClip created at runtime

Hi all,
my first post here, I hope you'll be able to help me with my problem.

I'm making a simple application that takes users input (text), formats it the way user specified, and displays text on stage. Later on, user can move (drag & drop) text all over the stage and can rotate it as well. The problem came with this rotation functionality. After user clicks Generate button, I create a TextField and place it into a MovieClip. When I try to rotate the MovieClip, it suddenly dissapears. I can't understand why this is so, 'cause I can access (and set) the .x and .y properties without a problem, but .rotation gives me problems. Later on I realised that it's not the MovieClip (the "container") that reacts on different events, it's the TextField inside it that reacts to MOUSE_DOWN/UP and other events. Why is this so? Anyway, here's the code:

Code:
function generateMC(event:MouseEvent):void {
    if(input.text != "" && color != "" && cbFonts.selectedIndex > -1 && cbSize.selectedIndex > -1){
        var myFormat:TextFormat = new TextFormat();
        myFormat.font = font;
        myFormat.size = size;
        myFormat.color = color;
        
        var container:MovieClip = new MovieClip();
        container.x = 100;
        container.y = 300;
        var writing:TextField = new TextField();
        writing.text = input.text;
        writing.setTextFormat(myFormat);
        writing.autoSize = TextFieldAutoSize.LEFT;
        writing.selectable = false;
        container.addChild(writing);
        stage.addChild(container);
        
        container.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
        container.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
        stage.addEventListener(MouseEvent.MOUSE_UP, stopRotating);
       
        function startDragging(event:MouseEvent):void
        {
            offsetX = event.stageX - container.x;
            offsetY = event.stageY - container.y;
            localX = container.mouseX;
            if(localX > (container.width * 0.9)){ /* if the mouse was pressed at the last 10% of containers width */
                rotateBool = true;
                stage.addEventListener(MouseEvent.MOUSE_MOVE, rotateContainer);
            } else {
                stage.addEventListener(MouseEvent.MOUSE_MOVE, dragContainer);
            }
        }

        function rotateContainer(event:MouseEvent):void {
            container.rotation += 2;                /* this isn't working! Why? 
            event.updateAfterEvent();
        }

        function stopRotating(event:MouseEvent):void
        {
            if(rotateBool == true){
                rotateBool = false;
                stage.removeEventListener(MouseEvent.MOUSE_MOVE, rotateContainer);
            }
        }
       
        function dragContainer(event:MouseEvent):void
        {
            container.x = correctX(event.stageX - offsetX, container.width); /* functions correctX/Y are used to prevent the user from dragging mc out of stage */
            container.y = correctY(event.stageY - offsetY, container.height);
            event.updateAfterEvent();
        }       
       
        function stopDragging(event:MouseEvent):void
        {
            stage.removeEventListener(MouseEvent.MOUSE_MOVE, dragContainer);
        }
}
}
Thanx, hope I was clear. Cheers from Croatia!

Ivan

p.s. this is a very cool site/forum, I think it's a great resource for all level AS programmers, so keep up the good work!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)  
Old 03-04-08, 11:06
Junior Member
 
Join Date: Mar 2008
Posts: 6
Rep Power: 0
ibreslau is on a distinguished road
Re: Problem with rotating MovieClip created at runtime

Fixed! I just needed to embed the fonts!
Cheers!

Ivan
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
Actionscript 3 Accessing Programmatically Created Textfield Pherankh advanced Actionscript 3.0 0 21-10-08 01:51
Rotating header 2 Flep FlepStudio utilities 11 19-10-08 01:31
Rotating header Flep FlepStudio utilities 4 20-08-08 14:30
Problema Con Rotating Header v.1 Thundereo Actionscript 3.0 base 2 16-04-08 14:14
Rotating header Aesop0827 HELP free utilities 1 26-02-08 18:56


All times are GMT. The time now is 22:52.


Powered by vBulletin versione 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap


FlepStudio
by Filippo Lughi
P.IVA 03605860406