creating object according to the switch case value - actionscript-3

i have the following switch case:
switch (appModel.currentPage){
case "Programma":
case "Winkelwagen":
case "Films":
case "Contact":
if (page){
removeChild(page);
}
//here i would like to create a new object page that has the type of the switch.
i mean this: var page: getDefinitionByName(appModel.currentPage+"Page");
this doesnt work thou but it should be something like: "FilmsPage or ContactPage or ...".
addChild(page);
break;
Does anyone know how to do this?

var pageClass:Object = getDefinitionByName(appModel.currentPage+"Page");
var page:DisplayObject = new pageClass();
addChild( page );

PatrickS's answer should work, but you will need to make sure all the classes that you will use are referenced somewhere, or the compiler will skip over them, and not add them to your SWF.

Related

Changing image source attribute in Vue.js + TypeScript

So I have a simple img tag:
<img #error="replaceByDefaultImage" :src="urls.photos_base_url_small.jpg'"/>
And replaceByDefaultImage function looks like this:
replaceByDefaultImage(e: HTMLImageElement) {
e.src = '/img/default.png';
}
Now in case the photos_base_url_small is missing, the replaceByDefaultImage fires but it doesn't change the image source. Or at least it doesn't change on the HTML itself. Although it works if I use target like e.target.src = '/img/default.png'; but if I want to use target, I have to set any type to the event variable e and I prefer not to use this type. Any ideas?
replaceByDefaultImage(e: Event) {
(e.target as HTMLImageElement).src = '/img/default.png';
}
Found this solution. Looks fine I guess. Variable e is a type of event so we can't use it like image itself. We have to get the target element first.

How to call a global var document.getElementById into a function to get the .className

That's what I use to toggle between the Login and Register divs.
The following is actually working:
function myNavLogin()
{
document.getElementById("Content-Login").className = "Content-On";
document.getElementById("Content-Register").className = "Content-Off";
}
I want to call the next global variable:
var divLogin = document.getElementById("Content-Login");
var divRegister = document.getElementById("Content-Register");
Inside the function like this way:
function myNavLogin()
{
divLogin.className = "Content-On";
divRegister.className = "Content-Off";
}
The second example isn't working, I think because the variable isn't declared by the correct way or I am calling it bad... please help, thanks.
Regards, Chicler ;)
Your question is probably a simple variable scoping one, but here's a more thorough response anyway. Global variables are a horrible way to code. You should try to use a more object oriented approach. You should also consider keeping tag names out of your variable names, since markup is apt to change. Finally, when toggling classes, it's better to simply add and remove an "on" state and have the "off" state be the default. Here's an example:
var AccountLogic = function(){
this.elLogin = document.getElementById("Content-Login");
this.elRegister = document.getElementById("Content-Register");
this.login = function(){
this.elLogin.classList.add("content-on");
this.elRegister.classList.remove("content-on");}
}
}
var accountLogic = new AccountLogic();

Forced to use template?

This code from Dart worries me:
bool get isTemplate => tagName == 'TEMPLATE' || _isAttributeTemplate;
void _ensureTemplate() {
if (!isTemplate) {
throw new UnsupportedError('$this is not a template.');
}
...
Does this mean that the only way I can modify my document is to make it html5?
What if I want to modify an html4 document and set innerHtml in a div, how do I achieve this?
I am assuming you are asking about the code in dart:html Element?
The method you are referring to is only called by the library itself, and only in methods where isTemplate has to be true, for example this one. If you follow this link, you can also read what other fields/methods work like this.
innerHtml is a field in every subclass of Element which supports it, for example DivElement
Example:
DivElement myDiv1 = new DivElement();
myDiv1.innerHtml = "<p>I am a DIV!</p>";
query("#some_div_id").innerHtml = "<p>Hey, me too!</p>";

Flash QuickBox2d skinMc.gotoAndPlay(1);

I have this quickBox2d code to add a cricle to the stage:
var ball:QuickObject = sim.addCircle( {skin:skinMc, x:10, y:10, radius:3, density:0 } );
The skinMc contains animations so I want to be able to refer to it like this: skinMc.gotoAndPlay(5); but it says
Type Coercion failed: cannot convert skinMc$ to flash.display.MovieClip.
ball.gotoAndPlay(5); doesn't work either since it's a QuickObject, not an mc...
Any help will be appreciated
Thanks
ball.userData.gotoAndPlay(5);
userData will be a DisplayObject populated by QuickBox2D.
var sim:QuickBox2D = new QuickBox2D
var ball:QuickObject = sim.addCircle( {skin:skinMc, x:10, y:10, radius:3, density:0 } );
//something along these lines
So to reference the object you can use:
sim.gotoAndPlay("5");
im not 100% on what your doin but i installed both packages and created a quick document and it works fine on my machine.
if need be try this link http://www.emanueleferonato.com/2009/08/25/simplify-your-box2d-projects-with-quickbox2d/
if this fails,send me your file or else let me know how you go.

MediaWiki variant tabs

Anyone knows how to get the variant tabs to work as actual tabs and not as a drop down?
This is how sr.wikipedia.org has it:
and this is how I have it on my zablude.com/wiki/ page:
and I've tried everything I found and searched everywhere I could think of but I wasn't able to find a solution... anyone has any ideas how this works?
They hack it in JavaScript — see this piece of code at the bottom of Медијавики:Vector.js:
//to be able to switch the language variant (overrides the default buttons with more visible ones)
function tabWorkaround() {
if(mw.config.get('wgUserVariant') == 'sr') {
var tab_urls = {};
tab_urls[0] = document.getElementById('ca-varlang-0').getElementsByTagName('a')[0].href; //Ћирилица
tab_urls[1] = document.getElementById('ca-varlang-1').getElementsByTagName('a')[0].href; //Latinica
$('#p-variants').remove();
mw.util.addPortletLink('p-namespaces', tab_urls[0], 'Ћирилица');
mw.util.addPortletLink('p-namespaces', tab_urls[1], 'Latinica');
}
}
$(document).ready(tabWorkaround);
It would probably be cleaner to do it with a MediaWiki hook, though. The following code is untested, but should work if I haven't made any silly mistakes:
// show language variants as tabs in Vector skin
function tabWorkaround( &$skintemplate, &$links ) {
$links['namespaces'] += $links['variants'];
$links['variants'] = array();
return true;
}
$wgHooks['SkinTemplateNavigation::Universal'][] = 'tabWorkaround';
(In MW 1.17, this hook is only called from the Vector skin. In MW 1.18, it will affect all skins. If you don't want that, you could test whether $skintemplate->skinname == 'vector'.)
Try $wgVectorFeatures['collapsibletabs']['global'] = false;. That is intended for the dropdown on the other side, but might work for other dropdowns as well.