Dynamic Text Field in Multiple Frames?
A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Dynamic Text Field in Multiple Frames?

  1. #1
    Member
    Join Date
    Sep 2010
    Posts
    61

    Dynamic Text Field in Multiple Frames?

    Can you use the same dynamic text field in two separate frames?

    I have a button (movieclip) that I want to make multiple instances of with different labels. I have a dynamic text field in the movieclip, and a second frame for the rollover state.

    I also created a dynamic text field for the rollover state and gave it the same instance name as the first one. Shouldn't it display the same text across both states?

    I can post code if needed.

    Thanks,

    Ogaac

  2. #2
    Senior Member
    Join Date
    May 2010
    Posts
    178
    Post a sample fla in CS3 format to understand your structure better

    Poltuda

  3. #3
    Member
    Join Date
    Sep 2010
    Posts
    61
    I've got CS5, is there a way to save for earlier versions?

  4. #4
    Senior Member
    Join Date
    May 2010
    Posts
    178
    Export fla from CS5 to CS4 format and then if you have CS4, you can able to export it again into CS3 no other option.

    But you can post the swf to have a look of it.

    Poltuda

  5. #5
    Member
    Join Date
    Sep 2010
    Posts
    61
    I'm having difficulty replicating the issue, I took a different route and that's not working either. Sigh.

  6. #6
    Senior Member
    Join Date
    May 2010
    Posts
    178
    Can you post your swf file?

  7. #7
    Member
    Join Date
    Sep 2010
    Posts
    61
    Here's the .swf, it takes a second to load. I'm trying to optimize it :P

    So the button in the middle is the problem, its there for testing purposes. I'm trying to instantiate that button so it works like all the ones on top. Make sense?

    http://kyleaho.com/unionSiteFlash_Productions.swf

  8. #8
    Senior Member
    Join Date
    May 2010
    Posts
    178
    OK

    Now Post Your Code and some details of the structure and you are using.

    I will give a try....

    Regards

    Poltuda

  9. #9
    Member
    Join Date
    Sep 2010
    Posts
    61
    I appreciate all of your help by the way.

    Here's my button code:

    Actionscript Code:
    package {
       
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
        import flash.text.TextField;
        import flash.text.TextFormat;
         
        public class BtnClone extends MovieClip
        {
            private var labelField:TextField;
             
            public function BtnClone()
            {               
                labelField = new TextField();
                labelField.width = this.width;
                labelField.height = this.height;
                labelField.y = 0;
                var format:TextFormat = new TextFormat();
                format.align = "center";
                format.size = 24;
                format.font = "Verdana";
                format.color = "0xFFFFFF";
                       
                labelField.defaultTextFormat = format;
                addChild(labelField);
                                         
                mouseChildren = false;
                buttonMode = true;
               
                stop();
               
                addEventListener(MouseEvent.ROLL_OVER, onOver);
                addEventListener(MouseEvent.ROLL_OUT, onOut);
            }
           public function setLabel(label:String):void
                {
                labelField.text = label;
                }
            private function onOver(e:MouseEvent):void
                {
                gotoAndStop(2);
                }
           private function onOut(e:MouseEvent):void
                {
                gotoAndStop(1);
                }
            }
        }

    And my engine:

    Actionscript Code:
    package {
        import flash.display.MovieClip;
        import flash.events.Event;
        import flash.events.MouseEvent;
        import flash.geom.Point;
        import flash.display.Stage;
        import flash.display.SimpleButton;
        // COMMENTED OUT import caurina.transitions.Tweener;

        public class Engine extends MovieClip
        {
            //Ship vars
            private var ourShip:Ship;
            private var ourLaser:Laser;
            private var homeButton:HomeButton;
            private var managementButton:ManagementButton;
            private var productionButton:ProductionButton;
            private var newsButton:NewsButton;
            private var aboutUsButton:AboutUsButton;
            private var button:BtnClone; //THIS IS THE MALFUNCTIONING BUTTON
                   
            public function Engine():void
            {
                //BUTTONS TEST
                //THIS IS THE MALFUNCTIONING BUTTON
                button = new BtnClone();
                button.x = 350;
                button.y = 200;
                   button.setLabel("Home");
                addChild(button);       
                       
               
                //YOU CAN PROBABLY IGNORE ALL THIS
                //CREATE MENU
                homeButton=new HomeButton();
                addChild(homeButton);
                homeButton.x = 20;
                homeButton.y = 0;
               
                aboutUsButton=new AboutUsButton();
                addChild(aboutUsButton);
                aboutUsButton.x = 190;
                aboutUsButton.y = 0;
               
                managementButton=new ManagementButton();
                addChild(managementButton);
                managementButton.x = 400;
                managementButton.y = 0;
               
                productionButton=new ProductionButton();
                addChild(productionButton);
                productionButton.x = 610;
                productionButton.y = 0;
               
                newsButton=new NewsButton();
                addChild(newsButton);
                newsButton.x = 802;
                newsButton.y = 0;
               
               
                //CREATE SHIP
                ourShip=new Ship(new Point(stage.stageWidth/2,stage.stageHeight/1.05));
                addChild(ourShip);
                stage.addEventListener(MouseEvent.MOUSE_DOWN, fireLaser);
                           
                //GAME SWITCH EVENTS
                gameList.theDarkness.addEventListener (MouseEvent.CLICK, theDarkness);
                gameList.redStar.addEventListener (MouseEvent.CLICK, redStar);
                filmList.blacklight.addEventListener (MouseEvent.CLICK, blacklight);
                filmList.buckRogers.addEventListener (MouseEvent.CLICK, buckRogers);
                filmList.zeroG.addEventListener (MouseEvent.CLICK, zeroG);
               
                gameList.buttonMode = true;
                filmList.buttonMode = true;
            }       
                //BIO SWITCH FUNCTIONS
                private function theDarkness(e:Event):void
                {
                    propertyInfo.gotoAndStop(1);
                    trace("Get The Darkness Bio");
                }
                private function redStar(e:Event):void
                {
                    propertyInfo.gotoAndStop(2);
                    trace("Get Red Star Bio");
                }
                private function blacklight(e:Event):void
                {
                    propertyInfo.gotoAndStop(3);
                    trace("Get Blacklight Bio");
                }
                private function buckRogers(e:Event):void
                {
                    propertyInfo.gotoAndStop(4);
                    trace("Get buckRogers Bio");
                }
                private function zeroG(e:Event):void
                {
                    propertyInfo.gotoAndStop(5);
                    trace("Get Zero G Bio");
                }
            private function fireLaser(e:Event):void
            {
                //CREATE LASERS
                //Make sure mouse is trying to use menu bar.
                if (mouseY < 50)
                {
                ourLaser=new Laser(new Point(ourShip.x,ourShip.y));
                stage.addChild(ourLaser);
                // have ship check every frame, for laser to button hit
                ourShip.addEventListener(Event.ENTER_FRAME, hitCheck, false, 0, true);
                }
            }
            private function hitCheck(e:Event):void
            {
                //COLLISION DETECTION FOR LASERS AND BUTTONS
                if (ourLaser.hitTestObject(homeButton))
                {
                    trace("Get URL Home");
                    stage.addChild(new Explosion(stage, x+75, y+25));
                    stage.removeChild(ourLaser);
                    ourShip.removeEventListener(Event.ENTER_FRAME, hitCheck);
                    removeChild(homeButton);
                }
                if (ourLaser.hitTestObject(aboutUsButton))
                {
                    trace("Get URL About Us");
                    stage.addChild(new Explosion(stage, x+275, y+25));
                    stage.removeChild(ourLaser);
                    ourShip.removeEventListener(Event.ENTER_FRAME, hitCheck);
                    removeChild(aboutUsButton);
                }
                if (ourLaser.hitTestObject(managementButton))
                {
                    trace("Get URL Management");
                    stage.addChild(new Explosion(stage, x+475, y+25));
                    stage.removeChild(ourLaser);
                    ourShip.removeEventListener(Event.ENTER_FRAME, hitCheck);
                    removeChild(managementButton);
                }
                if (ourLaser.hitTestObject(productionButton))
                {
                    trace("Get URL Production");
                    stage.addChild(new Explosion(stage, x+675, y+25));
                    stage.removeChild(ourLaser);
                    ourShip.removeEventListener(Event.ENTER_FRAME, hitCheck);
                    removeChild(productionButton);
                }
                if (ourLaser.hitTestObject(newsButton))
                {
                    trace("Get URL News");
                    stage.addChild(new Explosion(stage, x+875, y+25));
                    stage.removeChild(ourLaser);
                    ourShip.removeEventListener(Event.ENTER_FRAME, hitCheck);
                    removeChild(newsButton);
                }           
            }
        }
    }

    Thanks again for all the help! Let me know if you need anything else.

    NOTE: As you can see I'm not using the dynamic text field anymore, but if you think that would work I'm more than willing to try it again.

  10. #10
    Member
    Join Date
    Sep 2010
    Posts
    61
    Can anyone tell me what's wrong with my button code? The error message is...

    code:
    1067: Implicit coercion of a value of type flash.text:TextFormat to an unrelated type Class.



    With the following code:

    package {

    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFormat;

    public class BtnClone extends MovieClip
    {
    private var labelField:TextField;
    private var format:TextFormat = new TextFormat();
    private var overFormat:TextFormat = new TextFormat();


    public function BtnClone()
    {
    labelField = new TextField();
    labelField.width = this.width;
    labelField.height = this.height;
    labelField.y = 0;

    format.align = "center";
    format.size = 24;
    format.font = "Verdana";
    format.color = "0xFFFFFF";

    overFormat.align = "center";
    overFormat.size = 18;
    overFormat.font = "Verdana";
    overFormat.color = "0x696969";

    labelField.defaultTextFormat = format;
    addChild(labelField);

    mouseChildren = false;
    buttonMode = true;

    stop();

    addEventListener(MouseEvent.ROLL_OVER, onOver);
    addEventListener(MouseEvent.ROLL_OUT, onOut);
    }
    public function setLabel(label:String):void
    {
    labelField.text = label;
    }
    private function onOver(e:MouseEvent):void
    {
    gotoAndStop (2);
    TextFormat = overFormat;
    }
    private function onOut(e:MouseEvent):void
    {
    gotoAndStop (1);
    TextFormat = format;

    }
    }
    }
    Last edited by ogaac; 10-18-2010 at 06:22 PM.

  11. #11
    Member
    Join Date
    Sep 2010
    Posts
    61
    I figured it out, for those interested here's my code:

    Actionscript Code:
    package {
       
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
        import flash.text.TextField;
        import flash.text.TextFormat;
         
        public class BtnClone extends MovieClip
        {
            private var labelField:TextField;
            private var format:TextFormat = new TextFormat();
            private var overFormat:TextFormat = new TextFormat();
           
             
            public function BtnClone()
            {               
                labelField = new TextField();
                labelField.width = this.width;
                labelField.height = this.height;
                labelField.y = 0;
                           
                format.align = "center";
                format.size = 24;
                format.font = "Verdana";
                format.color = "0xFFFFFF";
               
                overFormat.align = "center";
                overFormat.size = 24;
                overFormat.font = "Verdana";
                overFormat.color = "0x33FF00";
                                   
                labelField.defaultTextFormat = format;
                addChild(labelField);
                                         
                mouseChildren = false;
                buttonMode = true;
               
                stop();
               
                addEventListener(MouseEvent.ROLL_OVER, onOver);
                addEventListener(MouseEvent.ROLL_OUT, onOut);
            }
           public function setLabel(label:String):void
                {
                labelField.text = label;
                }
            private function onOver(e:MouseEvent):void
                {
                gotoAndStop (2);
                labelField.setTextFormat(overFormat);
                }
           private function onOut(e:MouseEvent):void
                {
                gotoAndStop (1);
                labelField.setTextFormat(format);
               
                }
            }
        }

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

Poll by Flashkit.com