Adobe Dreamweaver Forums



Last 10 THreads :         Basing new project on old project (Last Post : Stephen Windham - Replies : 2 - Views : 3 )           »          Performing a search within multiple .as files (Last Post : JohnnyDang - Replies : 0 - Views : 1 )           »          Conditional loop (Last Post : BKBK - Replies : 1 - Views : 2 )           »          change of state (Last Post : Mainmanian - Replies : 2 - Views : 3 )           »          Performing a search within multiple .as files (Last Post : JohnnyDang - Replies : 0 - Views : 1 )           »          Please point me to the correct topic section of thisForum (Last Post : GillyWilly - Replies : 4 - Views : 5 )           »          Writing a Dreamweaver Extension, where to start? (Last Post : ryodoan - Replies : 0 - Views : 1 )           »          pop up blocker jacking my login (Last Post : JoeyD1978 - Replies : 1 - Views : 2 )           »          Can't upload selected pdf's to remote server (Last Post : DontTazeMeBro - Replies : 5 - Views : 6 )           »          Video page not opening from link. (Last Post : Mad Dog - Replies : 4 - Views : 5 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Other Macromedia/Adobe Products > Flex
 
Tags:



Reply
  #1 (permalink)  
Old 10-31-2008, 06:27 PM
SiHoop
 
Posts: n/a
Diggs:
Default AS2 to AS3

I have 3 questions regarding my migration from AS2 to AS3.
First, in AS2, I could generate variables on the fly. For example, I could
write:
var textHolder=new MovieClip
textHolder.myVar=1
I believe that doing this in AS3 requires me to extend MovieClip and to
declare myVar in the sub-class. Is this correct?

Second, in the code below, a text field (i.e. tf) is a child of a Movie Clip
(i.e. textHolder), however, I don't seem to be able to control the text field
though the chain textHolder.tf For example, if I try the following:
trace("name="+e.target.tf.name), I get the error message: A term is undefined
and has no properties.
Is there another way to do this.

Third, I notice that the following line is very important:
textHolder.mouseChildren =false

Removing it allows me to use the following trace statement:
trace("name="+e.target.text)
What is happening here?



package{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.*;

public class Simon extends MovieClip{
private var tf:TextField=new TextField
private var myWordsArray:Array=[]
private var textFieldSpacing:int
private var format1:TextFormat
private var presentWord:String
private var presentWordNum:int
private var correctArray:Array=[]
public function Simon(){
var tempWordsArray:Array = "A KING LIVED IN A CASTLE".split("")
var myWords:String=""
//Add spaces between each of the characters, unless the character is a space
(omit the last character)...
for(var i:int=0;i<tempWordsArray.length-1;i++){
if(tempWordsArray[i] !=" "){
myWords+=tempWordsArray[i]+" "
}
}
//...now add the final character, minus an extra space
myWords+=tempWordsArray[tempWordsArray.length-1]
var myWordsArray:Array = myWords.split("");
var lineOffset:int = 0;
var presentWord:String=""
for (var counter:int=0; counter<myWordsArray.length; counter++) {
presentWord = "word"+counter.toString();
presentWordNum=counter
//Create a movie clip for each word in the string
format1=new TextFormat()
format1.size=48
var tf:TextField=new TextField
tf.autoSize=TextFieldAutoSize.LEFT
tf.selectable=false
tf.background=true
tf.text=myWordsArray[counter]
tf.setTextFormat(format1);
var textWidth:int=tf.width
var textHolder:MovieClip=new MovieClip
textHolder.addChild(tf)
textHolder.name=presentWord
textHolder.x=textFieldSpacing
textFieldSpacing+=textWidth
textHolder.buttonMode=true
textHolder.mouseChildren =false
addChild(textHolder)
textHolder.addEventListener(MouseEvent.CLICK, mc_CLICK)
}
return
}
private function mc_CLICK(e:Event):void{
trace("name="+e.target.name)
}
}
}



Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-31-2008, 06:27 PM
LuigiL
 
Posts: n/a
Diggs:
Default Re: AS2 to AS3

No, the MovieClip class is still dynamic so you can add properties. If you
extend MovieClip but you dont declare your subclass dynamic, then you cannot
add properties.

To access a display list you need to use getChildByName or getChildAt. If you
would add an instance name on your tf you can retrieve that tf using
getChildByName(), see attached snippet (assuming you assign an instance name in
the loop using tf.name = "tf";


You need to read up on the target and currentTarget properties of events.

//I've added a property to textHolder in the loop
var textHolder:MovieClip=new MovieClip
textHolder.identifier = "I'm just a word";

// and uncommented
//textHolder.mouseChildren =false

private function mc_CLICK(e:MouseEvent):void{
var clip:MovieClip = e.currentTarget as MovieClip;
trace("Holder: " + clip.name);
trace("Dynamic property: " + clip.identifier);
var tf:TextField = clip.getChildByName("tf") as TextField;
trace("tf text: " + tf.text);
}

Reply With Quote
Reply


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 07:19 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Cheap Car Insurance - Compare Motor Insurance
Endsleigh Car Insurance Natwest Car Insurance
More Than Car Insurance Norwich Union Car Insurance
Prudential Car Insurance Zurich Car Insurance
Inactive Reminders By Mished.co.uk