Frontendplace Blog

Sharing Frontend developing ideas

  • Adds

Archive for August, 2008

Typewriter class in actionscript

Posted by info on 25th August 2008

This is an example how to create a typeing effect without having to use masks. (you can repeat the text or add a pipe character )


import mx.utils.Delegate;

class myfolder.typingText { // replace myfolder with the folder structure you use
private var delayTime:Number;
private var destinationMc:MovieClip;
private var messageText:String;
private var currentChar:Number;
private var includePipe:Boolean; // include pipe character after text
private var doRepeat:Boolean; // repeat typeing after 5 sec

public function typingText(mcBot, mcRoom){
this.delayTime = 50;
this.destinationMc = null;
}
public function typeText(){
var dest = this.destinationMc;
if (dest && dest.html != null) {
dest.html = true;
dest.text = this.messageText.substr(0, this.currentChar);
if(this.includePipe)
dest.text = dest.text + "|";

this.currentChar++;
if (this.currentChar > this.messageText.length) {
if(this.doRepeat){
this.currentChar = 1;
_global.setTimeout(Delegate.create(this,typeText),5000);
}
} else {
_global.setTimeout(Delegate.create(this,typeText),this.delayTime);
}
}
}
public function startTyping(textParam, delayParam, destinationParam, repeat , pipe){
this.messageText = textParam;
this.delayTime = delayParam;
this.currentChar = 1;
this.destinationMc = destinationParam;
this.typeText();
this.includePipe = pipe;
this.doRepeat = repeat;
}

}

Insert in flashdocument:

import myfolder.typingText

var myText = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed vel est. Cras convallis quam non diam. ";

// textarea
var typing1 = new typingText();
typing1.startTyping(myText,200, taTypingText,true, false );
// dont use pipe in text area because a CR is generated and pipe end up under the last line

//inputtext
var typing2 = new typingText();
typing2.startTyping(myText.substr(0, 40),80, tiTypingText, true, true );

// textfield
var typing3 = new typingText();
typing3.startTyping(myText,500, dtTypingText, false, false );

Example:

Posted in 3D Tutorials | No Comments »

Solved Leak in IE

Posted by info on 12th August 2008

For javascripters it is well know that IE browsers have problems with memory leaking.. but this problem took me while to find..

On several sites I attach events based on the classname of an element. I have to remove these attached events on unload. So I did. but somehow I always have one element leaking in IE ( mostly an element that i didn’t attach anything on it, so that puzzled me) 

The problem was in the getEvent function I used to convert a fired event to W3C standard. this was my code:

function getEvent(e) {
 if (e == null) {
  e = window.event;
 }
 if (e == null) {
  return null;
 } 
if (!e.target) {
  e.target = e.srcElement;
 }
 // get parent if nodetype is textnode
     if (e.target.nodeType == 3) {
     e.target = e.target.parentNode;
 }
 if (!e.stopPropagation) {
  e.stopPropagation = function() {
   e.cancelBubble = true;
  }
 }
 if (!e.preventDefault) {
  e.preventDefault = function() {
   e.returnValue = false;
  }
 }
 return  e;
}

 

But calling this function caused the leak.
when I changed this function to this underlying code the leak was gone…….hooray!!!


/**
* Returns an event object that is normalized for cross-browser support.
*
* @param {Event} e Event object. Is allowed to be null.
* @returns {Event} A normalized event object.
*/
function getEvent(e) {
    if (e == null) {
  e = window.event;
 }
 if (e == null) {
  return null;
 }
 if (!e.target || !e.stopPropagation || !e.stopPropagation) e = W3CEvent(e);
 
 return  e;
}

/**
* Returns a synthetic event object with partial compatibility with W3C events
*
* @param {Event} e Event object.
* @returns {event} The partial W3C event object.
*/
function W3CEvent(e) { 
    if (!e) e = window.event;
    var event = {
        _event: e,              // In case we really want the IE event object
        type: e.type,           // Event type
        target: e.target?e.target:e.srcElement,   // Where the event happened
        relatedTarget: e.fromElement?e.fromElement:e.toElement,
        keyCode: e.keyCode,
       
        // Mouse coordinates
        clientX: e.clientX,
        clientY: e.clientY,
        screenX: e.screenX,
        screenY: e.screenY,
       
        // Key state
        altKey: e.altKey,
        ctrlKey: e.ctrlKey,
        shiftKey: e.shiftKey,
        charCode: e.keyCode,

        // Event management functions
        stopPropagation: function(){this._event.cancelBubble = true;},
        preventDefault: function(){this._event.returnValue = false;}
    }
    return event;
};

why???? if someone can tell me why please respond..

Posted in 3D Tutorials | No Comments »

archiving folder with mac’s automator

Posted by info on 1st August 2008

When you want a folder to be back-upped inside a folder with a datename for version control. It is very easy to do this with apple’s own automator.Go to automator (in your application folder or with right mouse click on a finder element -> more -> automator)  and select the following actions:

  • Ask for Finder Items 
  • Create Archive
  • New Dated Folder

Enter a name for your zipfile in the create archive folderchoose a dateformat in the new date folder actionselect ‘move passed items to the new folder’ in the new date folder action.and your done.  archivefolder

Posted in Other tutorials | No Comments »