Tag Archives: tutorial

Zend Framework – Disable Zend Layout

What’s Zend Layout

Everybody knows that sometimes you need header and footer for almost every page. In Zend Framework you don’t need to include them in every template page, as it will be if you were using Smarty for instance. You just need to use Zend_Layout. It’s easy and it’s helpful.

What if you don’t need layout for a controller action?

Well if you have to have a given controller action with no use of Zend_Layout, you just need to disable it.

How …

… simply by placing this line in you controller action:

$this->_helper->layout->disableLayout();

jQuery – accessing a child element

Let’s assume you have a <div> element with 20 <a> tags inside, and each <a> tag has a <span> somewhere inside it. If you’d like to access all those spans you should use this jQuery line:

$('div a').children(':first-child')

Common mistake is to query like that:

$('div a:first-child')

but that is completely other thing, and will return the first <a> tag, not the <span> inside all of them.

Flex Javascript communcation example

First of all you’ve to have both files for JavaScript and Actionscript  3 to make the communication successful. I don’t remember where exactly I found the tutorial, maybe it was on the official Adobe’s documentation page, but as I’ve written before I’m going to share my experience with the ExternalInterface options of Flex.

First of all you’ve to add this at the beginning of the page with the simple js code:

var jsReady = false;
function isReady()
{
return jsReady;
}

function pageInit()
{
jsReady = true;
}

of course the pageInit() function should be called onload of the body. It simply sets the JavaScript part to be ready for communication, after initialize the page. Than a small part of the javascript should be written for really speaking with the Flex application.

var swfReady = false;

function setSWFIsReady() {
swfReady = true;
}

function getSWF(movieName) {
if (navigator.appName.indexOf(“Microsoft”) != -1) {
return window[movieName];
} else {
return document[movieName];
}
}

function callFlexApp() {
if (swfReady) {
getSWF(“flash_movie”).methodInFlex(param_value1, param_value2);
}
}

Where flash_movie is the id of the object / embed pair.

First of all the JavaScript can begin to call methods in Flex only after the Flex application has returned that it has been initialized. That happens in Flex within the following file:

package communicator {

import flash.events.TimerEvent;
import flash.external.*;
import flash.utils.Timer;

public class Communicator
{

public function init():void {

if (ExternalInterface.available)
{

var containerReady:Boolean = isContainerReady();
if (containerReady)
{
setupCallbacks();
}
else
{
var readyTimer:Timer = new Timer(100);
readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
readyTimer.start();
}

}
else
{
trace(“External interface is not available for this container.”);
}

}

private function isContainerReady():Boolean
{
var result:Boolean = ExternalInterface.call(“isReady”);
return result;
}

private function setupCallbacks():void
{
ExternalInterface.addCallback(“callFlexApp”, callFlexApp);
ExternalInterface.call(“setSWFIsReady”);
}

private function timerHandler(event:TimerEvent):void
{
var isReady:Boolean = isContainerReady();
if (isReady)
{
Timer(event.target).stop();
setupCallbacks();
}

}


private function callFlexApp(param1:int, param2:int):void
{
// this function is called from javascript

}

}

}

That’s the short description how to set up a communcation between JavaScript and Flex.

Flex 3 ComboBox disabled options

Recently I had to make a drop down menu in a Flex Application, or either ComboBox in the Flex terminology, where some of the items in it should be disabled. Many tutorials explained how to make the entire ComboBox disabled, but that was out of scope here.The idea is to have a large range, let’s say the numbers from 1 to 30, and make 1 to 10 disabled, and the others – selectable. After reading the documentation of Adobe it appears that this is not possible with just using some attribute of the default component.

Of course in the case of only three you can make it with radio buttons or checkboxes. Here after the question how to write such a component, the answer is:

Have you considered using radio buttons rather than a combo box?

Well, no, I’m not! I’d like to make it for such a big range. In my case it was more than 200 options, the case with radio buttons is not enough.

Finally I found a sample of a disabled list items on http://joshblog.net but yet again it was dealing with list, not a combo box. In my case the combo box has very important built in events and fires different kind of them in any special situation. That’s why I don’t think this sample could do the work.

Actually as it seems easy and usefull, almost nowhere there was such a component. In Adobe’s blogs I found interesting post http://blogs.adobe.com/aharui/2007/06/disabling_list_selection.html where the author describes how to make a list with that properties, and somewhere in the comments I found the component at last:

Hi Alex,
I’m seeking the disabling combobox. Your posting give me some ideals.
And now, I have implmented the disabling ComboBox and List using my
method.
Your blog is very helpful for me.Thanks.

I have put my disabling ComboBox to my blog

Here it is http://wmcai.blog.163.com/blog/static/4802420088945053961/

Thanks to the author there is a demo and download. Soon I’ll share my experience with the disabled combo box items.