Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > Adobe Web Programming > Flash (all versions)
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Flash (all versions) section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 22nd, 2005, 09:59 AM
Registered User
 
Join Date: Aug 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to JeremyL Send a message via AIM to JeremyL Send a message via MSN to JeremyL Send a message via Yahoo to JeremyL
Default centering dynamic text fields with a dot spacer

Here's what I have so far but it's nto working as intended. Help would be appreciated.


I need to find the center of the document and then work from there to keep seperate dynamic text fields centered on the document after concantenating them along with a dot spaced between the fields. Here is what I have - any help woudl be appreciated. (Flash MX 2004)

var gotComp = String(DAT_Company).length > 0 ? 1 : 0;
var gotDiv = String(DAT_Division).length > 0 ? 1 : 0;
var gotAddr = String(DAT_Address).length > 0 ? 1 : 0;
var gotCity = String(DAT_City).length > 0 ? 1 : 0;
var gotState = String(DAT_State).length > 0 ? 1 : 0;
var gotZip = String(DAT_Zip).length > 0 ? 1 : 0;
var gotCnty = String(DAT_Country).length > 0 ? 1 : 0;

var CityStateZip = '';
var dotSpacing = 10;
var fldSpacing = 5;

// company/division
if(gotComp){
 DAT_Company_txt.text = DAT_Company;
}
if(gotDiv){
 DAT_Division_txt.text = DAT_Division;
}

if(gotAddr){
 DAT_Address_txt.text = DAT_Address;
}

// city, state, zip
CityStateZip = (gotCity)? DAT_City : '';
CityStateZip += (gotCity && gotState)? ', ' + DAT_State : DAT_State;
CityStateZip += (CityStateZip.length > 0)? ' ' + DAT_Zip : DAT_Zip;
CityStateZip += (CityStateZip.length > 0)? ' ' + DAT_Country : DAT_Country;
CityStateZip_txt.text = CityStateZip;

// sort fields.
var origA = new Array();
var newA = new Array();

origA[0] = DAT_Company_txt.text;
origA[1] = DAT_Division_txt.text;
origA[2] = DAT_Address_txt.text;
origA[3] = CityStateZip_txt.text;

// grab the valid values for the fields
for(i = 0; i < origA.length; i++){
 if(String(origA[i]).length > 0){
  newA.push(origA[i]);
 }
}

// assign values to the fields again
DAT_Company_txt.text = newA[0];
DAT_Division_txt.text = newA[1];
DAT_Address_txt.text = newA[2];
CityStateZip_txt.text = newA[3];

// Dot Positioning
currentX = DAT_Company_txt._x;

//if(DAT_Company_txt.text != '' && DAT_Division_txt.text != ''){
if(DAT_Company_txt.text != ''){
 textWidth = DAT_Company_txt.textWidth;
 dot1_mc._x = currentX + textWidth + dotSpacing;
 currentX = dot1_mc._x + fldSpacing;
}


// dot positioning
currentX = DAT_Address_txt._x;

if(DAT_Address_txt.text != '' && CityStateZip_txt.text != ''){
 textWidth = DAT_Address_txt.textWidth;
 dot2_mc._x = currentX + textWidth + dotSpacing;
 currentX = dot2_mc._x + fldSpacing;
 CityStateZip_txt._x = currentX;
}


 
Old August 24th, 2005, 08:23 AM
Registered User
 
Join Date: Aug 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to JeremyL Send a message via AIM to JeremyL Send a message via MSN to JeremyL Send a message via Yahoo to JeremyL
Default

Ok I've got it centering properly however now for some reason between first text field and the dot spacer, there is a white space that increases with the amount of text in the first text field. Any way to eliminate this?

Code to this point:

var gotComp = String(DAT_Company).length > 0 ? 1 : 0;
var gotDiv = String(DAT_Division).length > 0 ? 1 : 0;
var gotAddr = String(DAT_Address).length > 0 ? 1 : 0;
var gotCity = String(DAT_City).length > 0 ? 1 : 0;
var gotState = String(DAT_State).length > 0 ? 1 : 0;
var gotZip = String(DAT_Zip).length > 0 ? 1 : 0;
var gotCnty = String(DAT_Country).length > 0 ? 1 : 0;

var CityStateZip = '';
var dotSpacing = 10;
var fldSpacing = 5;
var lineWidth = 10;
var xMax = this.regPoints.xMax


// company/division
if(gotComp){
    DAT_Company_txt.text = DAT_Company;
}
if(gotDiv){
    DAT_Division_txt.text = DAT_Division;
}

if(gotAddr){
    DAT_Address_txt.text = DAT_Address;
}

// city, state, zip
CityStateZip = (gotCity)? DAT_City : '';
CityStateZip += (gotCity && gotState)? ', ' + DAT_State : DAT_State;
CityStateZip += (CityStateZip.length > 0)? ' ' + DAT_Zip : DAT_Zip;
CityStateZip += (CityStateZip.length > 0)? ' ' + DAT_Country : DAT_Country;
CityStateZip_txt.text = CityStateZip;

// sort fields.
var origA = new Array();
var newA = new Array();

origA[0] = DAT_Company_txt.text;
origA[1] = DAT_Division_txt.text;
origA[2] = DAT_Address_txt.text;
origA[3] = CityStateZip_txt.text;

// grab the valid values for the fields
for(i = 0; i < origA.length; i++)
{
    if(String(origA[i]).length > 0){
        newA.push(origA[i]);
    }
}

// assign values to the fields again
DAT_Company_txt.text = newA[0];
DAT_Division_txt.text = newA[1];
DAT_Address_txt.text = newA[2];
CityStateZip_txt.text = newA[3];

// Line starting position
lineWidth = 0; // Initialize to 0
lineWidth = DAT_Company_txt.textWidth;
lineWidth += DAT_Division_txt.textWidth;
lineWidth += (fldSpacing * 2);
lineWidth += (dotSpacing * 2);




if(DAT_Company_txt.text != '' && DAT_Division_txt.text != '')
{
    currentX = ((this._width - lineWidth) / 2);
    dat_Company_txt._x = currentX;
    textWidth = DAT_Company_txt.textWidth;
    dot1_mc._x = currentX + textWidth + dotSpacing;
    currentX = dot1_mc._x + fldSpacing;
    dat_division_txt._x = currentX + dotSpacing;
}

// New line starting position
currentX = 0; // re initialize to 0
lineWidth = 0; // re initialize to 0
lineWidth += DAT_Address_txt.textWidth;
lineWidth += CityStateZip_txt.textWidth;
lineWidth += (fldSpacing * 2);
lineWidth += (dotSpacing * 2);
currentX = ((this._width - lineWidth) / 3);

// Text Positioning
if(DAT_Address_txt.text != '' && CityStateZip_txt.text != '')
{
    DAT_Address_txt._x = currentX;
    textWidth = DAT_Address_txt.textWidth;
    dot2_mc._x = currentX + textWidth + dotSpacing;
    currentX = dot2_mc._x + fldSpacing;
    CityStateZip_txt._x = currentX;
}








Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't set text property of dynamic text box sreerajrs ASP.NET 1.0 and 1.1 Professional 1 May 31st, 2006 09:39 PM
Pictures in Dynamic text fields kocken85 Flash (all versions) 1 February 11th, 2005 10:58 AM
Fields in a dynamic table? Roshu Javascript How-To 12 January 10th, 2005 09:04 AM
Adding dynamic fields ivnavin Crystal Reports 0 December 17th, 2004 03:35 PM
alignment of text on dot matrix using vb...urgent syed rose VB How-To 1 July 8th, 2004 06:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.