Recently, while working on my previously mentioned infamous project, I ran into the need for a rich text/HTML editor (rte). I had developed one using AS2 and the Macromedia component set and it worked pretty well until it came time to insert an image tag in to the mix. I had a nice ability of browsing the local system using MDM’s Zinc from the CD and then saving copies of the files into the CD’s working directory on the hard drive. The problem came when I started to realize the very poor support for the image tag in an HTML textField.
Not long thereafter I saw a post for www.flashtexteditor.com‘s editor. After trying it out and noticing how it seemed to do a better job at handling the insertion of images – I bought a copy to save time and headaches. Not far into adding it to my application I realized the need to hook up the browse feature to the already present “browse” button. If you are familiar with the component you will remember that when you insert an image it pulls a window component up with controls to set the properties of the image. The documentation (and Igor, the creator himself – I emailed him) mention that you can use the “browse” event and listen for it to set the “path” text box equal to the event object’s path property you set. I might note that in order to actually set the path text you must say: evtObj.path.text. I kept forgetting the .text being needed – I assumed the event object would be referencing that natively.
Next I wanted to reference some things in that pallet to hide (such as the ID, vSpace, etc) that a non-programming user wouldn’t need. Igor @ www.flashtexteditor.com told me this was not possible. I soon found that even the labels in the Image Attributes Window did not have instance names. I then set out to hack my way around the objects and make the thing display the way I needed it to. So for those of you that may have bought the component as well and are curious – here is my actionScript that I used to get references (that change every launch of the window component by the way). This was in my FLA so I am not sure if things will change for you based on how you are using it. Overall the component is good – the image support is not as close as I initially thought it was from the demo online but it suits my needs for now. Let me know if you have questions.
myBrowseListener = new Object();
myBrowseListener.browse = function(eo:Object){
pathBoxText = eo.path.text;
//
//References to stuff in the IMAGE panel
////ex. _root.depthChild[n].content. + a reference below
////eg. _root.depthChild1.content.vspace._visible would hide the vspace
//// component if the window it was in was in the the level _root.depthChild1
//// this is determined further down in the code and not required to know…
//vspace box
//vspace._visible = false;
//vspace label
//instance227._visible = false;
//hspace box
//hspace._visible = false;
//hspace label
//instance226._visible = false;
//autosize btn
//autosize_btn._visible = false;
//align box
//align._visible = false;
//align label
//instance228._visible = false;
//height box
//height._visible = false;
//height label
//instance225._visible = false;
//width box
//width._visible = false;
//width label
//instance224._visible = false;
//ID label
//instance223._visible = false;
//ID box
//id._visible = false;
//URL label
//instance222._visible = false;
//URL box
//url._visible = false;
//target label
//instance221._visible = false;
//target box
//target._visible = false;
//path label
//instance220._visible = false;
//path box
//src._visible = false;
//browse button
//browse_btn._visible = false;
//ok button
//ok_btn._visible = false;
//remove button
//remove_btn._visible = false;
//
}
//ref to the rich text editor’s image window browse button
rte.addEventListener(“browse”, myBrowseListener);
function readyImagePanel(pathStr){
//function to hide non-wanted items on the image panel
///////////////////////////////////////////////////
//hide stuff
///////////////////////////////////////////////////
for(i in pathStr){
//if it’s name contains “instance” (not a named instance)
if(i.indexOf(“instance”) > -1){
for(p in pathStr[i]){
//it’s a label so find out what it’s value is
if(pathStr[i].initText == “URL:” || pathStr[i].initText == “ID:” || pathStr[i].initText == “target:”){
pathStr[i]._visible = false;
}
}
}
//boxes (components)
if(i.indexOf(“id”) > -1 || i.indexOf(“url”) > -1 || i.indexOf(“target”) > -1 || i.indexOf(“autosize_btn”) > -1){
pathStr[i]._visible = false;
}
//save reference
if(i.indexOf(“height”) > -1){
heightBox = pathStr[i];
}
if(i.indexOf(“width”) > -1){
widthBox = pathStr[i];
}
if(i.indexOf(“ok_btn”) > -1){
okButton = pathStr[i];
}
//relayout out the remaining items
//path box
if(i.indexOf(“src”) > -1){
pathStr[i]._y -= 34;
}
if(pathStr[i].initText == “Path:”){
pathStr[i]._y -= 34;
}
//align box
if(i.indexOf(“align”) > -1){
pathStr[i]._y += 34;
}
if(pathStr[i].initText == “Align:”){
pathStr[i]._y += 34;
}
//width box
if(i.indexOf(“width”) > -1){
pathStr[i]._y -= 44;
}
if(pathStr[i].initText == “Width:”){
pathStr[i]._y -= 44;
}
//height box
if(i.indexOf(“height”) > -1){
pathStr[i]._y -= 44;
}
if(pathStr[i].initText == “Height:”){
pathStr[i]._y -= 44;
}
//hspace
if(i.indexOf(“hspace”) > -1){
pathStr[i]._y -= 44;
}
if(pathStr[i].initText == “HSpace:”){
pathStr[i]._y -= 44;
}
//vspace
if(i.indexOf(“vspace”) > -1){
pathStr[i]._y -= 44;
}
if(pathStr[i].initText == “VSpace:”){
pathStr[i]._y -= 44;
}
//browse button – this is scary – it moves it’s _y in relation to it’s height it seems
//so that 1.5 moves it 1.5 times it’s height
pathStr.browse_btn._y -= 1.15;
pathStr.browse_btn._x -= 3.3;
}
}
///////////////////////////////////////////////
//this listener is used to check if we click on the control button to insert an image
var listener:Object = new Object();
listener.click=function(o:Object)
{
for(i=0;i<1000;i++){
//loop through the first 1000 depths to find what depths are being used by the window component
if(eval(“_root.depthChild”+i) != undefined){
trace(“_root.depthChild”+i);
_root.imgWindowPath = “_root.depthChild”+(i-1);
}
}
switch (o.target._name) {
case “image”:
trace(“loading image window – monitor load”);
monitorImageWindow();
break;
}
}
rte.image.addEventListener(“click”, listener);
function monitorImageWindow(){
this.onEnterFrame = function(){
var cPath = eval(_root.imgWindowPath + “.content”);
//is that window done loading?
if(cPath._complete == true){
readyImagePanel(cPath);
delete this.onEnterFrame;
}
}
}