Coding swf in order to force running in my site - actionscript-3

I recently have secure https on my site.
So I'd like to update few coding lines in my swf flash games.
Now I have this:
path = _url.substring(0,22);
if (path == "http://lnx.sinapsi.org" || path == "http://win.sinapsi.org")
{
play();
}else{
stop();
getURL("http://www.sinapsi.org","_parent");
}
But I need adding also the https path, how?
I tried this:
path = _url.substring(0,23);
if (path == "https://lnx.sinapsi.org" || path == "https://win.sinapsi.org")
{
play();
}else
path = _url.substring(0,22);
if (path == "http://lnx.sinapsi.org" || path == "http://win.sinapsi.org")
{
play();
}else{
stop();
getURL("http://www.sinapsi.org","_parent");
}
But doesn't work :-(
Please, help. Thanks.

Try using the substr method instead...
substr( startPos:Number = 0, length:Number = 2147483647 max):String
Returns a substring consisting of the characters that start at the
specified startPos and with a length specified by length. The original
string is unmodified.
Your code would then have this logic...
path = _url.substr(0,23);
if (path == "https://lnx.sinapsi.org" || path == "https://win.sinapsi.org") { play(); }
else
{
path = _url.substr(0,22);
if (path == "http://lnx.sinapsi.org" || path == "http://win.sinapsi.org") { play(); }
else { stop(); getURL("http://www.sinapsi.org","_parent"); }
}
If all fails, then just check what the heck the compiler sees...
path = _url.substr(0,23);
trace("checking Path : " + path);
Disclaimer : This is an untested suggestion but it might work for you. Good luck.

It does not look AS3, more of AS1/AS2. I think that's what you want:
// Split url into Array by "/" character and get only domain string.
// That allows you to avoid guessing substr indexes.
domain = _url.split("/")[2];
// Switch looks more neat and elegant than barrage of ifs.
switch (domain)
{
case "lnx.sinapsi.org":
case "win.sinapsi.org":
play();
break;
default:
stop();
getURL("http://www.sinapsi.org","_top");
break;
}

Related

Can I use duplicate IDs on multiple <template> fragments?

Why does HTML5 validation fail when having duplicate element IDs but on different <template>. I'm planning to use only one template at a time so the actual DOM ID won't be duplicated.
something like:
<template id="companyAccount">
<li><label>Company: <input type="text" id="account_name"></label></li>
<li><label>Street: <input id="account_street" ...
...
</template>
<template id="residentialAccount">
<li><label>Name: <input type="text" id="account_name"></label></li>
<li><label>Street: <input id="account_street" ...
...
</template>
<script>
...
let template = $(isResidential ? '#residentialAccount' : '#companyAccount').get(0).content;
$('#account_info').empty().append(template.cloneNode(true));
</script>
As TJBlackman mentioned each value for id attributes must be unique. However when working with code it's up to you to determine if the code being imported contains a duplicate id. Additionally I've pretty much stopped using validators for the most part as they aren't well maintained (and the W3C's CSS validator is atrocious) and the consoles, proper error handling and using the XML parser for HTML5 will tell you pretty much everything you need to know.
You have a couple of options. You can use data-account="residential" (don't make the mistake of using camelCasing as that will eventually put you in direct conflict with the standards bodies) and detect the attribute via document.querySelectorAll:
function $(o)
{
var a = true;
try {document.querySelectorAll(o);}
catch(err) {a = false; console.log('Error: "'+o+'" is not a valid CSS selector.'); sound.notice();}
return (a && document.querySelectorAll && document.querySelectorAll(o)) ? document.querySelectorAll(o) : false;
}
Usage: $('[data-account="residential"]')[0].length and $('[data-account="residential"]')[0].value.
Alternatively you can do what I do with my platform which has things tightly integrated though this is the function I use that you might decide to slim down for your specific purposes. You can use document.createTreeWalker and literally go through every single element to scan for walker.currentNode.hasAttribute('id') to test against document.getElementById. This code is used before importing XML in to the DOM on my platform:
/******** part of larger ajax() function ********/
if (xhr.readyState == 4 && xhr.status != 204)
{}
//This code occurs within the above condition.
var r = jax_id_duplication_prevention(xhr.responseXML,param_id_container_pos,id_container);
if (r)
{
if (param_id_container_pos=='after') {id_container.parentNode.insertBefore(xml.getElementsByTagName('*')[0],id_container.nextSibling);}
else if (param_id_container_pos=='before') {id_container.parentNode.insertBefore(document.importNode(xml.getElementsByTagName('*')[0],true),id_container);}
else if (param_id_container_pos=='first')
{
if (id_container.childNodes.length > 0) {id_container.insertBefore(document.importNode(xml.getElementsByTagName('*')[0],true),id_container.firstChild);}
else {id_container.appendChild(document.importNode(xml.getElementsByTagName('*')[0],true));}
}
else if (param_id_container_pos=='inside') {id_container.appendChild(document.importNode(xml.getElementsByTagName('*')[0],true));}
else if (param_id_container_pos=='replace') {id_container.parentNode.replaceChild(document.importNode(xml.getElementsByTagName('*')[0],true),id_container);}
else if (param_id_container_pos=='fragment')
{
if (option.fragment) {delete option.fragment;}
option.fragment = document.importNode(new DOMParser().parseFromString(xhr.responseText,'application/xml').childNodes[0],true);
if (id_container && typeof id_container == 'function') {id_container();}
}
else {alert('Error: unknown position to import data to: '+id_container_pos);}
}
/******** part of larger ajax() function ********/
function ajax_id_duplication_prevention(xml,param_id_container_pos,id_container)
{
var re = true;
if (typeof id_container == 'string' && id_container.length > 0 && id_(id_container)) {id_container = id_(id_container);}
if (typeof option.id_fade == 'string' && option.id_fade.length > 0 && id_(option.id_fade)) {element_del(option.id_fade); option.id_fade = '';}
if (typeof xml.firstChild.hasAttribute == 'function')
{
if (xml.firstChild.hasAttribute('id') && xml.firstChild.getAttribute('id').length > 0 && id_(xml.firstChild.getAttribute('id')) && id_(xml.firstChild.id).parentNode.id=='liquid') {change(xml.firstChild.id,'fade');}
if (xml.firstChild.hasAttribute('id') && xml.firstChild.getAttribute('id').length > 0 && id_(xml.firstChild.id) && !id_(xml.firstChild.id).parentNode.id=='liquid') {re = false;}
else if (typeof document.createTreeWalker=='function')
{
var idz = [];
try
{
var walker = document.createTreeWalker(xml,NodeFilter.SHOW_ELEMENT,null,false);
while (walker.nextNode())
{
if (walker.currentNode.hasAttribute('id') && walker.currentNode.getAttribute('id').length > 0)
{
if (walker.currentNode.id==undefined && walker.currentNode.nodeName.toLowerCase()=='parsererror') {console.log('Error: a parser error was detected.');}
else if (walker.currentNode.id==undefined) {alert('walker.currentNode.nodeName = '+walker.currentNode.nodeName+'\n\n'+document.serializeToString(xml));}
else
{
for (var i = 0; i<id_('liquid').childNodes.length; i++)
{
if (id_('liquid').childNodes[i].nodeType==1 && id_(walker.currentNode.id) && is_node_parent(walker.currentNode.id,id_('liquid').childNodes[i]) && (param_id_container_pos!='replace' || walker.currentNode.id!=id_container.id))
{
if (param_id_container_pos != 'replace' && id_container != walker.currentNode.id) {element_del(id_('liquid').childNodes[i]);}//If changing operator test: ajax('get','?ajax=1&web3_url=/'+url_section()+'/'+url_page(),'replace',push_current_id());
}
}
var n = id_(walker.currentNode.id);
if (in_array(walker.currentNode.id,idz))
{
var fd = new FormData();
fd.append('ajax','error_xml');
fd.append('post_error','Duplicate id <code>'+walker.currentNode.id+'</code>.');
fd.append('post_url',url_window().split(url_base())[1].split('?')[0]);
fd.append('post_xml',new XMLSerializer().serializeToString(xml));
if (fd) {ajax('post',path+'/themes/',fd);}
modal.alert('Error: can not import XML, the id \''+walker.currentNode.id+'\' was detected twice in the layer being imported. Duplicated ID\'s break expected functionality and are illegal. While the XML content was not imported it is still possible that the related request was successful. It is possible to override this problem by simply doing a full request (press the Go button in your browser\'s graphic user interface) however if the id is referenced programmatically the website may exhibit unusual behavior.');
break;
setTimeout(function()
{
history.back();
push_reload();
console.log('Developer: duplicate id '+walker.currentNode.id+' was encounterted.');
if (status >= 9) {modal.xml('Duplicate ID Error', '%3Cp%3EError%3A%20the%20id%20%3Ccode%3E'+walker.currentNode.id+'%3C%2Fcode%3E%20occurred%20twice%20and%20therefore%20the%20page%20can%20not%20be%20viewed.%3C%2Fp%3E%3Cp%3EFor%20debugging%20and%20fixing%20purposes%20you%20should%20consider%20opening%20the%20URL%20in%20a%20new%20tab.%3C%2Fp%3E%3Cdiv%20class%3D%22center%20margin%22%3E%3Cinput%20onclick%3D%22modal.close()%3B%22%20tabindex%3D%223%22%20type%3D%22button%22%20value%3D%22Close%22%20%2F%3E%3C%2Fdiv%3E');}
else {modal.xml('Duplicate ID Error', '%3Cp%3EError%3A%20the%20id%20%3Ccode%3E'+walker.currentNode.id+'%3C%2Fcode%3E%20occurred%20twice%20and%20therefore%20the%20page%20can%20not%20be%20viewed.%3C%2Fp%3E%3Cdiv%20class%3D%22center%20margin%22%3E%3Cinput%20onclick%3D%22modal.close()%3B%22%20tabindex%3D%223%22%20type%3D%22button%22%20value%3D%22Close%22%20%2F%3E%3C%2Fdiv%3E');}
re = false;
},4000);
}
else {idz.push(walker.currentNode.id);}
}
if (id_(walker.currentNode.id) && (param_id_container_pos!='replace' && walker.currentNode.id!=id_container.id && !is_node_parent(walker.currentNode.id,id_container)))
{//ajax replace (carousel loader) complications if changed.
re = false;
modal.alert('Error: unable to import page, the id \''+walker.currentNode.id+'\' already exists in the DOM.');
break;
}
}
}
}
catch (err) {}//IE9
}
}
return re;
}
Regardless of how you approach addressing the issue it is not one addressed by the standards bodies and must be explicitly handled by developers. Failure to handle duplicate id attribute/values will result in the wrong element being chosen at some point which may quietly accrue compromised/malformed data over time that no one might notice for years and thus could easily hinder if not outright destroy any business relations effected by it. Good luck!

Highlighting default view in Telescope app

When you set the default view in admin settings, and you have multiple views checked to be available for user to switch, the default view doesn't get highlighted as "active".
To achieve this, in previous versions of Telescope (before RefactorScope) I modified the file client/components/menu/menu_component.js adding this (I had TOP as my default view, so I shamefully hardcoded it):
if (currentPath === "/" && getRoute(this) === "/top") {
itemClass += " item-active"
}
I understand, that editing Telescope source files was not wise thing to do, but it was the quickest and simplest solution.
Now, after the big Telescope refactor, I would like to do it the right way.
But the ultimate question is, what ist the right way to do this?
After some digging in Telescope source, I came to this solution:
Create a file named i.e. custom_view_menu.js in your custom package with this content:
getRoute = function (item) {
// if route is a Function return its result, else apply Router.path() to it
return typeof item.route == "function" ? item.route() : Router.path(item.route);
}
Template.menuItem.helpers({
itemClass: function () {
var itemClass = "";
var currentPath = Router.current().location.get().path;
if (this.adminOnly) {
itemClass += " item-admin";
}
if (getRoute(this) === currentPath || getRoute(this) === Meteor.absoluteUrl() + currentPath.substr(1)) {
// substr(1) is to avoid having two "/" in the URL
itemClass += " item-active";
}
if (this.label === Settings.get("defaultView") && currentPath === "/") {
itemClass += " item-active";
}
if (this.itemClass) {
itemClass += " "+this.itemClass;
}
return itemClass;
}
});
It's essentials copied from original source (https://github.com/TelescopeJS/Telescope/blob/master/packages/telescope-core/lib/client/templates/menu/menu_component.js) with this snipped added:
if (this.label === Settings.get("defaultView") && currentPath === "/") {
itemClass += " item-active";
}
I hope that it will help someone and I wasn't the only one trying to do this :)

if statement and visible statement dont work but the things inside it work? ACTIONSCRIPT 3

Yeah so here's my code
if(defaultmeter.visible = true)
{
meter1.visible = true;
meter1.x = 124.10;
meter.y = 63.10;
jizz.visible = false;
}
Thing is the things inside the { }
work but the the if statement doesnt apply
Like when defaultmeter is not visible, the stuff inside the {} still applies :C help please
If you do mc.visible = true so you assign the true value to mc.visible so you make mc visible which normally always true.
To compare in this level, we use == (equal) operator to check if two values are equal or the != (not equal, different ) to check if two values are not equal.
So in your case you can do :
if(defaultmeter.visible == true){
// instructions here
}
Or
if(defaultmeter.visible != false){
// instructions here
}
Or simply
if(defaultmeter.visible){
// instructions here
}
Well of course, you need to cover the other case as well, like this:
if(defaultmeter.visible == true)
{
meter1.visible = true;
meter1.x = 124.10;
meter.y = 63.10;
jizz.visible = false;
}else{
meter1.visible = false;
jizz.visible = true; //btw, jizz, seriously?
...
}
use like this if (defaultmeter.visible == true){}

Call to a possibly undefined method checkCollisions through a reference with static type Class

I know there are many questions answering something similar to this. However, this is specifically for Cory's collisiondetectionkit. I have installed it, and put the com folder in a random folder where I keep all my files. It looks like this:
This is the code which I have imported it with:
import com.coreyoneil.collision.*;
and this is where I call it in the code:
if(oCharUse == true){
if(CollisionList.checkCollisions(b1, oChar) == true){
trace("collision")
}
Try this, you should call the function on a CollisionList instance.
var collisionList:CollisionList = new CollisionList();
collisionList.addItem(oChar);
collisionList.addItem(b1);
...
var items:Array = collisionList.checkCollision();
if (items.length > 0)
{
for each (var obj:Object in items)
{
var ret1:Boolean = obj.object1 == oChar && obj.object2 == b1;
var ret2:Boolean = obj.object2 == oChar && obj.object1 == b1;
if (ret1 || ret2)
{
//oChar and b1 has collision
}
}
}
Here is source code of CollisionList and CDK
The main function is checkCollision of CollisionList and findCollisions of CDK, you may
see how it works.

Actions Script 3.0 if else statements

need to do several things by it's click event. I'm a beginner to this, so is there any other way to write this code? by clicking this button, it goes to next frame and according to statement several buttons will be visible or not. I wrote the code this way and it says there are syntax error, but I couldn't find any. Hope you guys understand this and will help me. :) Thank you!
review_btn.addEventListener(MouseEvent.CLICK, review1)
function review1(event:MouseEvent):void{
if(rvw1 == "Correct"){
gotoAndStop(3627);
help1.visible = false
}
else{
gotoAndStop(3627);
help1.visible = true
}
}
review_btn.addEventListener(MouseEvent.CLICK, review2)
function review2(event:MouseEvent):void{
if(rvw2 == "Correct"){
gotoAndStop(3627);
help2.visible = false
}
else{
gotoAndStop(3627);
help2.visible = true
}
}
review_btn.addEventListener(MouseEvent.CLICK, review3)
function review3(event:MouseEvent):void{
if(rvw3 == "Correct"){
gotoAndStop(3627);
help3.visible = false
}
else{
gotoAndStop(3627);
help3.visible = true
}
}
review_btn.addEventListener(MouseEvent.CLICK, review4)
function review4(event:MouseEvent):void{
if(rvw4 == "Correct"){
gotoAndStop(3627);
help4.visible = false
}
else{
gotoAndStop(3627);
help4.visible = true
}
}
review_btn.addEventListener(MouseEvent.CLICK, review5)
function review5(event:MouseEvent):void{
if(rvw5 == "Correct"){
gotoAndStop(3627);
help5.visible = false
}
else{
gotoAndStop(3627);
help5.visible = true
}
}
I'll take an attempt at it. It looks like the only difference is that in each method you need to match up "helpX".visible with "rvwX" equals the string "Correct", where X is a number from 1-5. The gotoAndStop() frame is the same regardless. Also, that all five are meant to be off the same button. I'm going to take an assumption that the clips 'help' are movieclips defined on the stage else if they are from something else I would store them in an array for looping through instead of 'building' the name and finding the reference that way just for clarity.
function review(event:MouseEvent):void {
for(var counter:int = 1; counter < 6; counter++){
this["help" + counter].visible = (this["rvw" + counter] != "Correct");
}
this.gotoAndStop(3627);
}
review_btn.addEventListener(MouseEvent.CLICK, review);
I think you have to do a class with 2 fields: "help" and "rvw" (let me call it "Switcher"). Also it may contain a function of setting visibility (may, not must, this function can also be in your main class):
Switcher.as:
import flash.display.MovieClip;
public class Switcher {
private var help:MovieClip;
private var rvw:String;
public function setVisibility() {
help.visible = !(rvw == "Correct");
}
}
Then you have to make an array of Switcher's objects in your main class and to use only one "review" handler:
function review(event:MouseEvent):void {
for each(var sw:Switcher in switchersArray) {
sw.setVisibility();
}
this.gotoAndStop(3627);
}
The code from previous answer will work correctly, but IMHO, creating an Array (or Vector) of similar objects is better than doing lots of help1, help2, help3 etc variables.